我有一个简单的 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/