首页 > 解决方案 > 如何在默认域的 Web.config 中同时启用基本和匿名身份验证?

问题描述

我有一个在 .Net 中使用框架版本 4.6.1 开发的 Web API 应用程序,我正在尝试使用具有默认域的 web.config 文件启用基本和匿名身份验证,但它无法正常工作,任何人都可以帮助我启用使用 web.config .

我已经尝试了以下代码,但它不起作用

<system.webServer>
  <security>
    <basicAuthenticaion enabled="true" defaultLogonDomain="DomainName"/>
    <anonymousAuthenticaion enabled="true"/>
  </security>
</system.webServer>

标签: c#iisasp.net-web-api2webapi

解决方案


你应该添加一个标签,<authentication>并且还要注意和的拼写basicAuthenticationanonymousAuthentication你用basicAuthenticaionand拼写它们anonymousAuthenticaion)。

<system.webServer>
    <security>
      <authentication>
        <basicAuthentication enabled="true"/>
        <anonymousAuthentication enabled="true"/>
      </authentication>
    </security>
</system.webServer>

顺便说一句,如果您启用了 Lex Li 在评论中提到的匿名身份验证,其他身份验证方法可能会关闭。因此,请检查您的要求是否需要同时启用它们。


推荐阅读