asp.net - MVC Web Api 不允许 Windows 身份验证

标签 asp.net security authentication asp.net-web-api2

我有一个简单的 MVC Web api 2 IIS 托管应用程序,我想启用 Windows 身份验证(最初不使用 Owin)。我在我的开发计算机上运行它并作为本地 IIS 运行。

因此,根据我的发现,我需要将以下内容添加到 web.config

1:到下一节的身份验证模式=“Windows”

<system.web>
  <compilation debug="true" targetFramework="4.5.1"/>
  <httpRuntime targetFramework="4.5.1"/>
  <authentication mode="Windows" />
</system.web>

2:然后添加以下内容

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

当我添加上述内容并运行应用程序(在 Dev studio 中进行调试)时,出现以下错误

HTTP 错误 500.19 - 内部服务器错误

配置错误此配置部分不能在此路径中使用。当该部分被锁定在父级别时,就会发生这种情况。锁定可以是默认设置 (overrideModeDefault="Deny"),也可以通过位置标记使用 overrideMode="Deny"或旧的allowOverride="false"显式设置。

然后它专门指向这个网络配置条目

配置来源:

37:     <authentication>
38:       <windowsAuthentication enabled="true"/>
39:     </authentication>

有人知道我为什么会得到这个吗?

此外,我注意到当我切换到 IIS Express 时,在项目属性中,Windows 身份验证被设置为禁用,并且呈灰色,因此我也无法在此处设置它。

预先感谢您的帮助!

最佳答案

如果您阅读 applicationHost.config,您将看到与身份验证相关的部分已被锁定并且无法在 web.config 中覆盖,

<section name="windowsAuthentication" overrideModeDefault="Deny" />

因此,您需要在 applicationHost.config 中指定,而不是在 web.config 中。 IIS 和 IIS Express 都有这样的限制。

关于asp.net - MVC Web Api 不允许 Windows 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23235391/

相关文章:

asp.net - 如何在响应重定向之前调用 javascript

php - 有什么好的方法可以防止恶意代理用户访问您的站点?

.htaccess - 使用 htaccess,将用户重定向到 SSL 域并从那里登录是否安全?

.net - ASP.NET 表单例份验证和 "No Authentication"子文件夹

mysql - 仅获取数据库的个人记录而不是所有记录

java - Android 将 MSAL 添加到应用程序会导致用户名不能为空

asp.net - ASP.NET 服务器错误中没有行号

asp.net - 如何解决 ASP.NET、VB.NET 中的 session 问题?

c# - 截断时间将列表转换为可为空

security - CSRF 不是浏览器安全问题吗?