views:

520

answers:

2

Hi guys, is it possible to prevent browsing of a folder contents in an ASP.NET web application other than creating a default page, say using web.config? I would like to avoid using IIS for this if possible.

Thanks

+2  A: 

If you are using IIS7, you can use web.config files for this. Specify a <location> tag for the desired folder, and give it a <directoryBrowse> sub-tag, ie:

<location path="path to your folder">
  <system.webServer>
    <directoryBrowse enabled="false" />
  </system.webServer>
</location>
Remy Lebeau - TeamB
Remy, thanks for the info. This didn't work on my ASP.NET development server (not IIS) using Visual Studio 2008. i made following change.<location path="Images">any ideas?
SoftwareGeek
+1  A: 

The previous answer system.webServer -> directoryBrowse is new and can be used when your site is running under IIS7 (be it debugging or otherwise) only, it will not work in IIS6. In IIS6 you need to do it using the IIS management console.

Colin
colin, thanks for the clarification.
SoftwareGeek