Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Directory Browse in Web.Config

Tags:

I have a WebSite and I woud like Deny Directory Browser from a web.config file.

Here the code I'm using placed in the ROOT. Does not work. I'm testing it Locally so with URL LIKE http://localhost:3214/ I can still browser the directory fro CMS.

  • What I'm doing wrong?
  • Should it work even on Local Machine?

Thanks for your support!

<configuration>   <location path="Cms">     <system.webServer>       <directoryBrowse enabled="false" />     </system.webServer>   </location> </configuration> 

Some resource:

http://blogs.iis.net/bills/archive/2008/03/24/how-to-enable-directory-browsing-with-iis7-web-config.aspx

http://www.expta.com/2008/03/configuring-virtual-directories-with.html

like image 207
GibboK Avatar asked Apr 05 '11 08:04

GibboK


People also ask

What does disabling directory browsing do?

Directory browsing allows anyone to see all the files in a folder and their contents. To help secure your site, you'll want to use your hosting's file manager to edit the files. You should always backup your site before making any changes.


2 Answers

First: not everything works in a <location> block.

I cannot find a positive statement that <system.webServer> isn't supported in a <location>, but I cannot find any cases where it is suggested that it is allowed. Evidence for this is in the (global) machine.config where the system.webserver section is defined to use the IgnoreSection handler: ie. it isn't processed by the standard System.Configuration implementation, and it is that standard implementation of config handling that provides support for <location>.

Try adding a web.config into the Cms folder with the directoryBrowse element to confirm that browsing is blocked.

like image 187
Richard Avatar answered Nov 13 '22 14:11

Richard


Gibbok, nothing is wrong here, Don't panic :)

Assuming that you are browsing your website from the built-in server inside Visual Studio, This is typically a normal case.

I'm pretty sure that if you moved to IIS with the above code, Directory browsing will behave just like what you want it to be.

Give it a try and host this website in IIS, and let us know what happened, Thanks.

like image 38
Mohammed Swillam Avatar answered Nov 13 '22 12:11

Mohammed Swillam