我想保护名为admin的文件夹中的网站管理区域

时间:2011-06-22 08:40:54

标签: asp.net

我想保护我的网站管理区域,在名为admin的文件夹中,我希望允许用户浏览所有网站页面,但管理区域必须按用户名和&密码请帮帮我这样做。

4 个答案:

答案 0 :(得分:1)

configuration的{​​{1}}部分添加以下内容。

web.config

<location path="Admin"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> 表示<deny users="?"/>用户无法访问unauthenticated文件夹。

答案 1 :(得分:0)

参考Configuring Specific Files and Subdirectories

  

可以应用配置设置   通过使用a来获取特定资源    用适当的标签   路径属性。 path属性可以   用于标识特定文件或   子目录唯一的   配置设置适用。只有一个   文件路径可以在路径中使用   属性。

<configuration>
  <system.web>
    <sessionState cookieless="true" timeout="10"/>
  </system.web>

  <!-- Configuration for the "sub1" subdirectory. -->
  <location path="sub1">
    <system.web>
      <httpHandlers>
        <add verb="*" path="sub1" type="Type1"/>
        <add verb="*" path="sub1" type="Type2"/>
      </httpHandlers>
    </system.web>
  </location>

  <!-- Configuration for the "sub1/sub2" subdirectory. -->
  <location path="sub1/sub2">
    <system.web>
      <httpHandlers>
        <add verb="*" path="sub1/sub2" type="Type3"/>
        <add verb="*" path="sub1/sub2" type="Type4"/>
      </httpHandlers>
    </system.web>
  </location>
</configuration>

答案 2 :(得分:0)

您应该在admin文件夹中放置一个web.config文件,并且除了必须具有访问权限的用户或角色之外,拒绝所有用户的访问:

  <system.web>
    <authorization>
        <allow roles="admins"/>
        <allow users="user1,user2"/>
        <deny users="*"/>
    </authorization>
  </system.web>

答案 3 :(得分:-1)

使用.htaccess和.htpasswd 您可以在http://www.htaccesstools.com/htpasswd-generator/

生成这些文件
相关问题