There are two standard ways to setup default page and should work as is:
1. Run From Visual Studio (In VS, Right Click on your desired Page and Select Set As Start Page)
2. Run From IIS (7 and above). Add following code on
Web.Config
inside configuration node:
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="MyPage.aspx" />
</files>
</defaultDocument>
</system.webServer>
Refer:
Default Document <defaultDocument> | Microsoft Learn[
^]
Additionally, you can also use Redirect using HTTPHandler (This is more for some logic implementation behind the scene) -
How to set the Default Page in ASP.NET?[
^]
UPDATE:
For Razor applications, you can try following approaches:
1. Routing. Refer:
Introduction to Razor Pages in ASP.NET Core | Microsoft Learn[
^]
edit the
@page
directive in the Index.cshtml and MyXYZ.cshtml files to configure the routes.
/* MyXYZ.cshtml.cs */
@page "/"
/* Index.cshtml.cs */
@page "/Index"
This applies explicit routes for the two pages, so that the MyXYZ Razor Pages page becomes the root page, and the Index page maps only to /Index.
2. Use configuration to change the root folder for Razor pages
builder.Services.AddRazorPages()
.AddRazorPagesOptions(options => {
options.RootDirectory = "/Content";
});
OR
builder.Services.AddRazorPages().WithRazorPagesRoot("/Content");
Refer:
Routing in Razor Pages | Learn Razor Pages[
^]