我在将站点部署到服务器时遇到错误。尝试加载主页或在IIS中的新站点上访问身份验证时,我收到错误:

配置错误:无法在此路径上使用此配置节。当节在父级锁定时,会发生这种情况。锁定是默认情况下(overrideModeDefault=“Deny”),或由具有overrideMode=“拒绝”或旧版的位置标记allowOverride=“false”。

更多细节可以在这里找到,在场景7中匹配我的十六进制错误代码。

上面链接站点上给出的解决方案是在applicationHost.config文件中的错误部分中设置Allow for overrideModeDefault。在我的例子中,在system.webServer中的“安全”下。但如果我查看本地计算机上的applicationHost.config(该站点已正确部署),则该部分设置为“拒绝”。

如果此解决方案是正确的,那么我的本地实例在使用相同的web.config时如何正常运行?根据我的applicationHost.config,该部分应该被锁定,但实际上没有。我宁愿不更改applicationHost.config文件,因为该服务器上还有许多其他站点在运行。还有其他解决方案吗?


当前回答

要解决此问题,请打开IIS Express applicationhost.config。此文件存储在C:\Users[您的用户名]\Documents\IISExpress\config\applicationhost.config中

VS2015+的更新:config文件位置为$(solutionDir).vs\config\applicationhost.config

查找以下行

<section name="windowsAuthentication" overrideModeDefault="Deny" />
<section name="anonymousAuthentication" overrideModeDefault="Deny" />
<add name="WindowsAuthenticationModule" lockItem="true" />
<add name="AnonymousAuthenticationModule" lockItem="true" />

将这些行更改为

<section name="windowsAuthentication" overrideModeDefault="Allow" />
<section name="anonymousAuthentication" overrideModeDefault="Allow" />
<add name="WindowsAuthenticationModule" lockItem="false" />
<add name="AnonymousAuthenticationModule" lockItem="false" />

保存并刷新Asp.net页面。

其他回答

浏览到“C:\Windows\System32\inetsrv\config”(此处需要管理员权限)打开applicationHost.config

注意:在IISExpress和Visual Studio 2015中,applicationHost.config存储在$(solutionDir).vs\config\applicationHost.config中

查找错误消息页面的“配置源”部分中显示的部分。对我来说,这通常是“模块”或“处理程序”

将overrideModeDefault属性更改为Allow

所以整条线现在看起来像:

<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />

保存文件后,页面在我的浏览器中加载良好。

警告:在64位Windows上编辑applicationHost.config

Powershell启用功能的方式(Windows Server 2012+)-根据需要进行微调:

Install-WindowsFeature NET-Framework-Core
Install-WindowsFeature Web-Server -IncludeAllSubFeature
Install-WindowsFeature NET-Framework-Features -IncludeAllSubFeature
Install-WindowsFeature NET-Framework-45-ASPNET -IncludeAllSubFeature
Install-WindowsFeature Application-Server -IncludeAllSubFeature
Install-WindowsFeature MSMQ -IncludeAllSubFeature
Install-WindowsFeature WAS -IncludeAllSubFeature

我注意到一个类似的答案,但在我的案例中,我使用IIS配置编辑器来查找我想要“解锁”的部分。

然后我复制了路径并在我的自动化中使用它来解锁,然后再更改我想要编辑的部分。

. "$($env:windir)\system32\inetsrv\appcmd" unlock config -section:system.webServer/security/authentication/windowsAuthentication
. "$($env:windir)\system32\inetsrv\appcmd" unlock config -section:system.webServer/security/authentication/anonymousAuthentication

我在设置override=“允许”值时遇到了问题(这里已经提到)。。。。。。但在x64位系统上。。。。。。。我的32个记事本++是在幻象中拯救他们。切换到记事本(x64位O/S上的64位应用程序)允许我保存设置。

参见:

http://dpotter.net/technical/2009/11/editing-applicationhostconfig-on-64-bit-windows/

相关文本:

我正在运行的一个问题要求我查看并可能编辑applicationHost.config。此文件位于%SystemRoot%\System32\inetsrv\config。看起来很简单。我可以很容易地从命令行找到它,但当我在我最喜欢的编辑器(Notepad++)中加载它时,我得到了一个文件未找到的错误。结果是,32位应用程序的System32文件夹被重定向到SysWOW64。似乎无法使用32位应用程序查看System32文件夹。想想看吧幸运的是,64位版本的Windows附带64位版本记事本。尽管我不喜欢它,但至少它起作用了。

在我的案例中,服务器上未启用.NET Framework功能下的“HTTP激活”。因此,对于Windows Server 2012,对我有效的解决方案是:

服务器管理器->添加角色和功能->功能->确保在要使用的.NET Framework版本下选中“HTTP激活”