Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict folder access in asp.net

How to restrict folder access in asp.net like I don't want any other to see my Uploads folder in browser by link http://www.example.com/Uploads

like image 798
Asad Avatar asked Sep 23 '10 09:09

Asad


People also ask

How can prevent direct access to files and folders in ASP NET MVC?

You have to set hiddenSegments in your web config for your Upload folder. You can also set it through IIS. YourSite > Request Filtering > Hidden Segments. Once you set hidden segments, anyone can't access file using url.

How do I change authorization in web config?

You can configure the <authorization> element at the server level in the ApplicationHost. config file, or at the site or application level in the appropriate Web. config file. You can set default authorization rules for the entire server by configuring authorization rules at the server level.


1 Answers

For the future generation the answer which works for me is to use hidden segments.

If you want to secure e.g. Uploads folder go to your root Web.config and add into <system.webServer> following element:

<security>   <requestFiltering>     <hiddenSegments>       <add segment="Uploads"/>     </hiddenSegments>   </requestFiltering> </security> 

This will prevent all users from direct access to Uploads folder and its content.

like image 107
Lukáš Kotrba Avatar answered Sep 21 '22 05:09

Lukáš Kotrba