【问题标题】:Setting IIS to protect admin folder设置 IIS 以保护 admin 文件夹
【发布时间】:2011-03-24 18:31:55
【问题描述】:

我在我的 .NET 应用程序中使用 windows 身份验证,是否可以设置 IIS,这样只有 admin 组中的用户才能访问 admin 文件夹,其他人会出错?

它在哪里做呢?在代码中?还是在 IIS 中有设置?

【问题讨论】:

    标签: .net active-directory admin


    【解决方案1】:

    为 Windows 身份验证配置 Web 应用程序

    要为您的 Web 应用程序配置 Windows 身份验证,请按以下步骤操作:

    • 单击开始,指向程序,指向管理工具,然后单击 Internet 信息服务。
    • 出现 Internet 信息服务 MMC。展开计算机,然后展开使用 Windows 身份验证的网站。
    • 单击您的网站应用程序。
    • 在“操作”菜单上,单击“属性”。
    • 在“属性”中,单击“目录安全”选项卡。
    • 在匿名访问和身份验证控制下,单击编辑。
    • 在身份验证方法中,单击以选择集成 Windows 身份验证。单击以清除所有其他复选框。
    • 点击确定。
    • 在“属性”中,单击“确定”。您的 Web 应用程序现在已配置为接受有效的用户帐户。

    然后在您的 web.config 中,启用 Windows 身份验证。

    <authentication mode="Windows" />
    

    您还需要在 web.config 中启用 RoleManage
    AspNetWindowsTokenRoleProvider 在 machine.config 中定义,因此您只需进行设置。

    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"></roleManager>
    

    然后您可以允许和拒绝特定用户或用户组(角色)

    <configuration>
    <!-- empty means files at root path -->
     <location path="">
      <system.web>
        <authorization>
          <!--Allowing any user of Administrators group,
            you can provide more separating by comma-->
          <allow roles="domainname\Administrators" />
          <deny users="*" />    <!-- * mean any user-->
        </authorization>
      </system.web>
     </location>
    </configuration>
    
    <configuration>
    <!-- means all files inside AdminFolder -->
     <location path="AdminFolder">
      <system.web>
        <authorization>
          <!--Allowing any user of Administrators group,
            you can provide more separating by comma-->
          <allow roles="domainname\Administrators" />
          <deny users="*" />    <!-- * mean any user-->
        </authorization>
      </system.web>
     </location>
    </configuration>
    

    我已经对其进行了测试,它确实有效。继续阅读How To: Use Windows Authentication in ASP.NET 2.0

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      • 2013-07-09
      • 1970-01-01
      相关资源
      最近更新 更多