0

When I run my application on localhost I get a directory listing and have to click on 'Index.aspx' to view the page.

I have already set the Set As Start Page to 'Index.aspx', which means when I press 'F5', 'Index.aspx' is opened.

This works fine, but when navigating through the site, if there is a link, such as '/FolderName', I get a directory listing, and have to manually change the URL to '/FolderName/Index.aspx'.

I believe this is because by default, the default page is 'Default.aspx'?

Is it possible to change this to 'Index.aspx'? It would save me a lot of time!

voretaq7
  • 79,345
  • 17
  • 128
  • 213
Curtis
  • 109
  • 1
  • 8
  • Where do you want to change it -- in web server (IIS 7) or Visual Studio? – LazyOne Jul 05 '11 at 13:04
  • Visual Studio, IIS is fine as I can use the 'Home Directory' options – Curtis Jul 05 '11 at 13:06
  • TBH I'm not 100% sure if my answer will work in VS (do not currently have one around to check -- you may need to reload project to see changes in VS). – LazyOne Jul 05 '11 at 13:10

1 Answers1

2

Place this into web.config in root folder of your site (if you have one already then just add appropriate section):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="Index.aspx" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

The above will add Index.aspx as the default document. If you want to remove all other default documents -- add <clear /> before <add value="Index.aspx" /> line:

<system.webServer>
    <defaultDocument>
        <files>
            <clear />
            <add value="Index.aspx" />
        </files>
    </defaultDocument>
</system.webServer>
LazyOne
  • 3,014
  • 1
  • 16
  • 15
  • whoa! +1 to get you past 666 reputation... – BenGC Jul 05 '11 at 13:10
  • @BanGC LOL! Thnx – LazyOne Jul 05 '11 at 13:11
  • Wish I could upvote too but hasn't solved my problem :/ I don't understand how this would work anyway as the web.config isn't read when opening a directory? – Curtis Jul 05 '11 at 13:12
  • @Curl These instructions tell web server to use Index.aspx as default document when accessing folder. It _should_ work in VS-bundled server as well (this definitely works in IIS and IIS Express). – LazyOne Jul 05 '11 at 13:16
  • @Curt I recommend installing IIS Express or even IIS -- http://msdn.microsoft.com/en-us/library/58wxa9w5.aspx – LazyOne Jul 05 '11 at 15:28