Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ASP.NET Core Razor pages Default page #9729

Closed
SherryCXL opened this issue Apr 25, 2019 · 5 comments
Closed

Change ASP.NET Core Razor pages Default page #9729

SherryCXL opened this issue Apr 25, 2019 · 5 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question

Comments

@SherryCXL
Copy link

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 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.

@DamianEdwards DamianEdwards added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 25, 2019
@angelru
Copy link

angelru commented Apr 25, 2019

I have the same issue.

I delete the Index.cshtml or change the name for example: Main.cshtml then it works.

@mkArtakMSFT
Copy link
Member

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

@mdpopescu
Copy link

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?

@mkArtakMSFT
Copy link
Member

@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.

@mdpopescu
Copy link

Thank you, much appreciated.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question
Projects
None yet
Development

No branches or pull requests

5 participants