允许对web.config中的单个文件夹进行匿名身份验证?

Chr*_*ell 43 asp.net authentication web-config

所以这是场景,我有一个使用自定义身份验证和成员资格提供程序的Asp.Net应用程序,但我们需要允许完全匿名访问(即)应用程序中的特定文件夹.

在IIS管理器中,您可以设置文件夹的身份验证模式,但设置将保存在C:\Windows\System32\inetsrv\config\applicationHost.config文件中,如此处所述

为了使安装更容易,如果我可以在我的web.config中设置它会很好,但经过几次尝试后我认为这可能是不可能的.

有没有人知道呢?

非常感谢

Tim*_*wis 55

第一种方法是使用<location>配置标记修改web.config ,并<allow users="?"/>允许匿名或<allow users="*"/>全部:

<configuration>
   <location path="Path/To/Public/Folder">
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如果该方法不起作用,则可以采用以下方法,该方法需要对IIS applicationHost.config进行少量修改.

首先,在C:\ Windows\System32\inetsrv\config\applicationHost.config中将anonymousAuthentication部分的overrideModeDefault从"Deny"更改为"Allow":

<section name="anonymousAuthentication" overrideModeDefault="Allow" />
Run Code Online (Sandbox Code Playgroud)

overrideMode是IIS的安全功能.如果在applicationHost.config中系统级别不允许覆盖,则无法在web.config中执行任何操作来启用它.如果您在目标系统上没有此级别的访问权限,则必须与托管服务提供商或系统管理员进行讨论.

其次,在设置overrideModeDefault="Allow"之后,您可以将以下内容放在web.config中:

<location path="Path/To/Public/Folder">
  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication enabled="true" />
      </authentication>
    </security>
  </system.webServer>
</location>
Run Code Online (Sandbox Code Playgroud)

  • 原帖专门引用了applicationHost.config文件.如果原始帖子与您的方案的特定限制不匹配,对答案的低调投票似乎很苛刻. (11认同)
  • 不幸的是,情况并非如此,因为overrideMode是IIS的安全功能.如果在applicationHost.config中系统级别不允许覆盖,则无法在web.config中执行任何操作来启用它.因此,如果您的目标系统没有该级别的访问权限,则必须与托管服务提供商或系统管理员进行讨论. (2认同)
  • 根据反馈更新了答案,请再看看. (2认同)

Ser*_* S. 44

使用<location>配置标记,并<allow users="?"/>仅允许匿名或<allow users="*"/>全部使用:

<configuration>
   <location path="Path/To/Public/Folder">
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

  • 这是我第一次尝试,但它不起作用.我怀疑这些位置授权设置仅在使用Forms身份验证运行时才有效. (13认同)
  • 这似乎是Chris Fewtrell的情况.当然,使用Windows身份验证,您设置这些内容似乎并不重要. (3认同)