Set Your Own Default Document With ASP.Net 4.0

I really like the IIS7 Manager for Remote Administration tool. Between that and Visual Studio 2010, most of what needs to be done to configure an ASP.NET application on a web server can be done painlessly.

What I've run into though is that VS2010 uses default.aspx for the main page to auto-load for the site. If there is another page already in existence that has a higher priority within IIS, then the other page will load. To get around this, I've used the IIS7 Manager to adjust the page load order. BUT, when republish my site, it sets the page load order back to the default again! Not the end of the world, but it's a bit of a hassle.

To get around this issue and to be sure that the default page you desire is loaded once the code is published to the server, you should consider setting the default document within the web.config file of your specific project. This will assure a more consistent and compatible experience should you need to move between servers or hosted environments (like Dev, QA, and Production).

Here is the code you can add to your project's web.config file to manage the default document:

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

If your default document is named something other than default.aspx, then just change that one setting to whatever you need it to be.

blog comments powered by Disqus