For ASP.NET Core MVC , we could get it easily by changing the route in app.UseMvc().
For Razor pages , MVC routing does not apply since Razor pages uses a different routing setup .But an error is generated when I tried to configure it using the AddRazorPagesOptions extension method to AddMvclike below:
services.AddMvc()
.AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/App", "");
});
What the error is show
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
Page: /App
Page: /Index
If I remove or rename “Pages/Index.cshtml” , it worked . But this workaround seems to be not reasonable. I wonder whether there is any other methods to change Razor pages Default page without changing the original one.
I have the same issue.
I delete the Index.cshtml or change the name for example:Main.cshtml then it works.
Thank you for your feedback.
Index page is considered the default and is part of the default convention. If you'd like to change it you should provide your custom convention: https://docs.microsoft.com/en-us/aspnet/core/razor-pages/razor-pages-conventions?view=aspnetcore-2.2
Sometimes I cannot help but think that MS employees intend to fit the stereotype. (You know the joke with the technically true but useless response.)
The only thing I can see on that page is the "configure a page route" section, which shows the exact example that the OP says is not working. Was it so difficult to explain exactly how to do what's being asked, instead of pointing to a long and complex page?
@mdpopescu I've put together a sample showing how to do this: https://github.com/mkArtakMSFT/Samples/blob/master/CustomPageRouteConvention/Conventions/DefaultRouteRemovalPageRouteModelConvention.cs
Hope this helps.
Thank you, much appreciated.
Most helpful comment
Sometimes I cannot help but think that MS employees intend to fit the stereotype. (You know the joke with the technically true but useless response.)
The only thing I can see on that page is the "configure a page route" section, which shows the exact example that the OP says is not working. Was it so difficult to explain exactly how to do what's being asked, instead of pointing to a long and complex page?