我有一个简单的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-内部服务器错误
Config Error此配置部分不能在此路径上使用。当节锁定在父级时,会发生这种情况。锁定默认情况下是(overrideModeDefault =“ Deny”),或者是由一个带有overlayMode =“ Deny”或旧版allowOverride =“ false”的位置标记显式设置的。
然后专门指向此Web配置条目
配置源:
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都有这样的限制。