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

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

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

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

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


当前回答

您需要解锁处理程序。这可以使用以下cmd命令完成:

%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/handlers

对于在IIS 8上遇到此错误的人,可能还有另一个信息,在我的情况下,是在Microsoft Server 2012平台上。我花了几个小时与执行appcmd后冒出的其他错误作斗争。最后,我能够通过删除Web服务器角色并再次安装来修复它。

其他回答

我注意到一个类似的答案,但在我的案例中,我使用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

要在应用程序级别(Web.Config)进行更改,请执行以下操作:

请从web.config中删除信任级别:

事实上,当我试图在托管服务器上托管我的网站时,我遇到了这个错误,我无法控制他们的服务器。从Applicationweb.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

浏览到“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

要解决此问题,请打开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页面。