使用Windows身份验证禁用ASP.NET应用程序的子文件夹上的身份验证

Ber*_*mme 3 c# windows asp.net authentication iis-7

是否可以使用Windows身份验证在ASP.net应用程序的一个或多个子文件夹上禁用Windows身份验证?

例如:

一个网站包含几个其他文件夹,其中包含整个应用程序的一部分:/ frontend,/ backend,/ login

bin文件夹与这些子文件夹处于同一级别,即网站的根目录.

所有这些子文件夹都包含使用位于网站根目录的bin文件夹中的二进制文件的页面.

用户在访问后端文件夹中的页面时必须输入Windows凭据,但在访问登录或前端文件夹中的页面时则不能.

我正在使用IIS7

有任何想法吗?

Ber*_*mme 12

找到了解决方案:

  • 调整applicationHost.config文件并将"overrideModeDefault"更改为"允许"以获取anonymousAuthentication和windowsAuthentication部分条目

                <section name="anonymousAuthentication" type="System.WebServer.Configuration.AnonymousAuthenticationSection" overrideModeDefault="Allow" />
                <section name="windowsAuthentication" type="System.WebServer.Configuration.WindowsAuthenticationSection" overrideModeDefault="Allow" />
    
    Run Code Online (Sandbox Code Playgroud)
  • 在web.config中为需要从Windows身份验证中排除的每个文件夹/文件添加了位置标记

       <location path="pathToDirOrFile">
         <system.webServer>
           <security>
            <authentication>
             <anonymousAuthentication enabled="true" />
             <windowsAuthentication enabled="false" />
            </authentication>
           </security>
          </system.webServer>
       </location>
    
    Run Code Online (Sandbox Code Playgroud)
  • 确保每个文件夹都包含一个单独的web.config文件,该文件禁用身份模拟

       <configuration>
        <system.web>
         <identity impersonate="false" />
        </system.web>
       </configuration>
    
    Run Code Online (Sandbox Code Playgroud)