简体   繁体   中英

How to deny access to folder in asp.net?

I am trying to deny access to folder in asp.net server, i put this web.config file inside the folder and still, I have access to filed in it, what shoul I do?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <authorization>
      <deny users ="*" />
    </authorization>
  </system.web>
</configuration>

Other problem that I had is to create new directory inside the folder I am trying to deny using the server dynamicly, how to do it? There is a way create a folder in asp.net server without ftp? I tried to use

Directory.CreateDirectory(Server.MapPath("~") + "newFolder"); 

but without success..

To deny access you can add this to the web.config file in your main folder:

<location path="folder_name_goes_here">
  <system.web>
    <authorization>
      <allow users="admin_1"/>
      <allow users="admin_2"/>
      <deny users="*"/>
    </authorization>
  </system.web>      
</location>         

To create a folder try to add "\\" between the MapPath and your folder :

 Directory.CreateDirectory(Server.MapPath("~") + "\\newFolder"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM