how to set start page in webconfig file in asp.net c#
How to set start page using Web.config
file. I have tried this code
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="index.aspx"/>
</files>
</defaultDocument>
</system.webServer>
But it did not work for me. I have set start page by right click on page in solution explorer then choose option set as start page but how can I do it programmatically?
Solution 1:
The following code worked fine for me. Kindly check other setting in your Web.config
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Login.aspx"/>
</files>
</defaultDocument>
</system.webServer>
Solution 2:
If your project contains a RouteConfig.cs file, then you probably need to ignore the route to the root by adding routes.IgnoreRoute("");
in this file.
If it doen't solve your problem, try this :
void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.AppRelativeCurrentExecutionFilePath == "~/")
Response.Redirect("~/index.aspx");
}
Solution 3:
I think this will help
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear />
<add value="index.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>