简体   繁体   中英

Change default page in ASP.NET Core Razor Page from Index to Home

I am changing Default Page

services.AddRazorPages(options =>
{
    //...
}).AddRazorPagesOptions(options =>
{
    options.Conventions.AddPageRoute("/Home", "");
});

but an exception occured

AmbiguousMatchException: The request matched multiple endpoints. Matches:
/Home
/Index

What can I do?

One option is to edit the @page directive in the Index.cshtml and Home.cshtml files to configure the routes :

/* Home.cshtml.cs */
@page "/"
/* Index.cshtml.cs */
@page "/Index"

This applies explicit routes for the two pages, so that the Home Razor Pages page becomes the root page, and the Index page maps only to /Index .


Note that with this approach, the call to AddPageRoute shown in your question is not needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM