Change ASP.NET Core Razor pages Default page
See original GitHub issueFor 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 AddMvc like 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Change a default Homepage in ASP.NET Core Razor Pages
Hello, I am creating an ASP.NET Core Razor Pages website, where the planned layout of the website will be the following navigation menu ......
Read more >Change default page in ASP.NET Core Razor ...
One option is to edit the @page directive in the Index.cshtml and Home.cshtml files to configure the routes: /* Home.cshtml.cs */ @page "/"...
Read more >Setting a Custom Default Page in ASP.NET Core Razor ...
We can set a custom default landing page for our ASP.NET Core Razor Pages apps! Here's how.
Read more >Setting A Custom Page As Landing Page In .Net Core ...
In this article, I will provide information on how to set a custom .NET Core Razor Page as your home/landing page.
Read more >Configuring Default Page in ASP.NET Core
First, give an appropriate name for your project (FirstCoreWebApplication), set the location where you want to create this project, and the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.