views:

50

answers:

4

I have a subdirectory in my root folder by the name files. I want to deny direct access to files under this directory. However my application can read and write to this directory programatically.

+2  A: 

If possible try to locate the files under the App_Data folder, which is intended as a store for data files that are used by the web application but not served directly to the users.

Fredrik Mörk
+1  A: 

in web.config, you can set up authorisation on the sub-directory

   <location path="name of subdirectory">
      <system.web>
         <authorization>
            <deny users="*"/>
         </authorization>
      </system.web>
   </location>

As Fredrik points out, the App_Data folder may be a better place to put these files. What type of files are they?

Russ Cam
I have a bin folder not App_Data. I have used it and got the result i was waiting for.
Manjoor
you can add an APP_DATA folder by right-clicking the project > ADD > Add ASP.NET folder > APP_DATA
Russ Cam
This article may be of use to you - http://msdn.microsoft.com/en-us/library/ex526337.aspx
Russ Cam
A: 

Add to your web.config section

   <location path="YourPath">
        <system.web>
            <authorization>
                <deny users="*" />
            </authorization>
        </system.web>
    </location>
Dewfy
A: 

Thanks for your comment guys. The web.config trick not working for me. I have used bin folder and it is giving satisfactory result.

Manjoor
you need to ensure that the path to the location in web.config is correct.
Russ Cam