41

I've just published my site in my server, but when I type in the browser www.mysite.com I get this error : HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.However if I type www.mysite.com/Home.aspx it loads correctly. So, how can I set the default page?? I already have this in my web.config :

<system.webServer>
   <defaultDocument>
     <files>
       <add value="Pages/Home.aspx" />
     </files>
   </defaultDocument>
  </system.webServer>
Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194
Norman
  • 433
  • 1
  • 5
  • 8

2 Answers2

89

ASP.NET WebForms

On the web.config file, try this to use the clear tag before:

<system.webServer>
  <defaultDocument>
    <files>
      <clear />
      <add value="Pages/Home.aspx" />
    </files>
  </defaultDocument>
</system.webServer>

Take a look here: http://www.iis.net/configreference/system.webserver/defaultdocument

ASP.NET MVC / ASP.NET CORE

Depending of the version of asp.net mvc you are using, you can have it on a different file (~/Global.asax.cs in v3 or older or ~/App_Start/RouteConfig.cs in v4 or newer). In both cases, you will see something register the routes, because asp.net mvc uses routes instead files like webforms. So, you can change the default values:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new 
        { 
            controller = "Home", // default controller
            action = "Index",  // default action on the controller
            id = UrlParameter.Optional
        }
    );
}

It is similar on the ASP.NET CORE.

Take a look here: http://www.codeproject.com/Articles/624181/Routing-Basics-in-ASP-NET-MVC

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194
  • 1
    Okey so if the default page which I want to load is placed at folder (in this case "Pages") Do I have to add "Pages/Home.aspx" in default document??? – Norman Aug 01 '13 at 19:32
  • Would this work for a document not in the root directory? for example if I want my default index to be "mydomain.com/folder1/index.html" – James Wierzba Jan 04 '17 at 20:01
  • @Felipe, It did not work with me, I am using IIS Express in ASP.net Web Form – user123456 Aug 04 '18 at 07:35
  • You wrote "It is similar on the ASP.NET Core" but there is no "id = UrlParameter.Optional", so it is an error. – ZedZip Aug 23 '19 at 09:35
  • If you use an ampersand, make sure you use & instead of & – live-love Jul 01 '21 at 15:02
5

Besides Felipe's answer, you can also do this from IIS.

Select Admin Tools --> IIS Manager --> Select your website from the list. Click on Default Document on the right hand side and Click Add. Move the entry to the top of the list using the arrows. You are done.

This will be overwritten each time you publish your site, however.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Icarus
  • 63,293
  • 14
  • 100
  • 115
  • 8
    Adding for any other weary travelers -- this is overridden next time you publish your site. – rrrhys Feb 05 '17 at 23:46