Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a dot net framework 4.6 application.

Initial home page loaded is https://domain/folder.

I need to be able to change this to https://domain/folder/file.

Any ideas or examples?

Thanks!

What I have tried:

I thought of doing this via IIS Rewrite, but could not get it to work.
I also thought of doing this via web.config, but again would not work.
Posted
Updated 8-Sep-23 10:46am
v3

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:
XML
<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.
HTML
/* 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
C#
builder.Services.AddRazorPages()
    .AddRazorPagesOptions(options => {
        options.RootDirectory = "/Content";
    });

OR
C#
builder.Services.AddRazorPages().WithRazorPagesRoot("/Content");
Refer: Routing in Razor Pages | Learn Razor Pages[^]
 
Share this answer
 
v2
Comments
Member 14972938 5-Sep-23 21:28pm    
Hi Sandeep,
Thanks for the reply, but I have already tried the IIS solution.
But it is not an aspx page it is a cshtml page.
So I tried value="folder/page name"

Also with the redirect
I only want to redirect if the following pattern is found "domain/folder"
then redirect to domain/folder/file

Ken
Sandeep Mewara 5-Sep-23 23:49pm    
You are talking of .NET Core Razor application then. For that, you can try two things:
1. Routing
2. Configuration change

Will update my answer to reflect more details.
If I understand what you're trying to do, you don't have to do anything. The default path, even if it ends in a folder, in a Razor app, is index.cshtml.

Now, if by "dynamic" you're talking about a different home page for different users, you can still write the default controller (whatever you're naming it) and in its Index method that returns the index.cshtml page, check the users profile and select the page you need to show the user, then simply do a
C#
return Redirect("url");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900