how to set start page in webconfig file in asp.net c#

129,038

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>
Share:
129,038
Bhupinder
Author by

Bhupinder

Updated on July 09, 2022

Comments

  • Bhupinder
    Bhupinder almost 2 years

    how to set start page using webconfig file .I have tried this code

    <system.webServer>
            <defaultDocument enabled="true">
                <files>
                    <clear />
                    <add value="index.aspx"/>
                </files>
            </defaultDocument>
        </system.webServer>
    

    But it didnot 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

  • Stefano Magistri
    Stefano Magistri over 6 years
    Session_Start is called every time and you forcing a user to be redirected at any postback
  • jboo
    jboo over 6 years
    @Aravin it means that it clears all informations that could be define in the files tag in other .config that affects your site.
  • LeCalore
    LeCalore over 4 years
    Why do we need to add all those? Is the order added the criteria used for displaying them?
  • Vipin G
    Vipin G over 4 years
    if you have .aspx page then add only these else it can be any page depends on language you are using.
  • Zar Shardan
    Zar Shardan over 3 years
    IgnoreRoute helped