How to set start page in Web.config file in asp.net c#
asp.netConfigurationWeb Configasp.net Problem Overview
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?
asp.net Solutions
Solution 1 - asp.net
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 - asp.net
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 - asp.net
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>
Solution 4 - asp.net
The same problem arrised for me when I installed Kaliko CMS Nuget Package. When I removed it, it started working fine again. So, your problem could be because of a recently installed Nuget Package. Uninstall it and your solution will work just fine.
Solution 5 - asp.net
For those using MVC views by now, add a rewrite rule to your web.config:
<rewrite>
<rules>
<rule name="Redirect to front" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/yourViewName" />
</rule>
</rules>
</rewrite>
Just put that in between the system.webServer tags of your configuration tags, replace yourViewName by your start page's view name (like Home), and you're done!
Works like a dream.
Solution 6 - asp.net
You can achieve it by code also, In you Global.asax file in Session_Start event write response.redirect to your start page like following.
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Response.Redirect("~/Index.aspx");
}
You can get redirect page name from database or any other storage to change the application start page while application is running no need to edit web.config or change any IIS settings