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

标签 asp.net authentication web-config

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

在 IIS 管理器中,您可以设置文件夹的身份验证模式,但设置保存在 C:\Windows\System32\inetsrv\config\applicationHost.config 文件 as described here

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

还有人知道吗?

非常感谢

最佳答案

第一种方法是使用 <location> 修改您的 web.config配置标签,和 <allow users="?"/>允许匿名或 <allow users="*"/>对于所有人:

<configuration>
   <location path="Path/To/Public/Folder">
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
</configuration>

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

首先,在 C:\Windows\System32\inetsrv\config\applicationHost.config 中将匿名身份验证部分的 overrideModeDefault 从“拒绝”更改为“允许”:

<section name="anonymousAuthentication" overrideModeDefault="Allow" />

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>

关于asp.net - 允许对 web.config 中的单个文件夹进行匿名身份验证吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10351075/

相关文章:

asp.net - WebForms 身份验证作为 MVC 过滤器

.net - 使用 protected 配置对web.config进行加密毫无意义吗?

asp.net - 如何排除XML中的根节点来显示菜单?

c# - 删除指定设计样本中的标签间距

c# - 从串口读取并显示结果

c# - 在数据绑定(bind)范围内创建一个变量

azure - 如何从 SSMS 2016 (Microsoft SQL Server) 注销?

java - 使用 JDBC 和 JSP 进行登录验证 : How to check if the username and Password entered by the user exists in the Database?

web-services - 跟踪到 LogSource 'All Events' 失败。企业库日志记录错误

java - Android 应用程序在访问本地主机时崩溃