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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With