Razor Pages Default Page in aspnetcore 2

Pretty sure it isn't possible. The docs say the runtime controls the search for Index as the default. I couldn't find where that happens in the current release, but IndexFileName is a static in the new internal PageRouteModelFactory class added to the upcoming release:

private static readonly string IndexFileName = "Index" + RazorViewEngine.ViewExtension;

It doesn't seem like it would be difficult to just add a config property to RazorPagesOptions, though. The ASP.NET guys are pretty responsive, I'd open a request as a GitHub issue and hope for the best.


In my case the ambiguity was caused by Pages/Index.cshtml left in project. This worked:

  1. options.Conventions.AddPageRoute("/App", "");
  2. remove or rename Pages/Index.cshtml

I solved the issue by using Microsoft.AspNetCore.Rewrite:

Then adding code to replace the default Index action, in my case with Portfolio:

var options = new RewriteOptions()
    .AddRedirect("^", "portfolio"); // Replace default index page with portfolio

More detailed article about rewrite options - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?tabs=aspnetcore2x