IIS 抱怨一个锁定的部分 - 我怎样才能找到它被锁定的地方?

Mic*_*tum 65 iis-7 web.config

我的 web.config 中有这个部分:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <security>
        <authentication>
            <anonymousAuthentication enabled="true" />
            <windowsAuthentication enabled="true" />
        </authentication>
    </security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

IIS7 崩溃并抱怨身份验证部分:

模块 AnonymousAuthenticationModule
通知 AuthenticateRequest
Handler StaticFile
错误代码 0x80070021
配置错误 此配置部分不能在此路径使用。当该部分锁定在父级别时会发生这种情况。锁定要么是默认的 (overrideModeDefault="Deny"),要么是由带有 overrideMode="Deny" 或旧版 allowOverride="false" 的位置标记显式设置的。

Config Source  
   69:  <authentication>
   70:    <anonymousAuthentication enabled="true" />
Run Code Online (Sandbox Code Playgroud)

所以解决这个问题的通常方法是进入%windir%\system32\inetsrv\config\applicationHost.config并解锁该部分:

    <sectionGroup name="system.webServer">
        <sectionGroup name="security">
            <section name="access" overrideModeDefault="Deny" />
            <section name="applicationDependencies" overrideModeDefault="Deny" />
            <sectionGroup name="authentication">
                <section name="anonymousAuthentication" overrideModeDefault="Allow" />
                <section name="basicAuthentication" overrideModeDefault="Allow" />
                <section name="clientCertificateMappingAuthentication" overrideModeDefault="Allow" />
                <section name="digestAuthentication" overrideModeDefault="Allow" />
                <section name="iisClientCertificateMappingAuthentication" overrideModeDefault="Allow" />
                <section name="windowsAuthentication" overrideModeDefault="Allow" />
            </sectionGroup>
Run Code Online (Sandbox Code Playgroud)

(或者,appcmd unlock config)。

奇怪的是:我已经这样做了,但它仍然抱怨。

我查找了 Locations(MVC 是我网站的名称,它是我正在使用的所有网站的根目录):

<location path="MVC" overrideMode="Allow">
    <system.webServer overrideMode="Allow">
        <security overrideMode="Allow">
            <authentication overrideMode="Allow">
                <windowsAuthentication enabled="true" />
                <anonymousAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
</location>
Run Code Online (Sandbox Code Playgroud)

还是会炸。我很困惑为什么会发生这种情况。我无法从 web.config 中删除它,我想找到根本问题。

有没有办法从 IIS 获取特定信息,哪个规则最终拒绝了我?

编辑:我能够使用 IIS7 管理控制台解决这个问题,方法是转到根目录(我的机器)并单击“编辑配置”并解锁那里的部分。我仍然想知道是否有更好的方法,因为我找不到它实际修改的文件。

tom*_*ing 98

制定了这些步骤来解决我的问题:

  1. 打开 IIS 管理器
  2. 单击左侧树中的服务器名称
  3. 右侧窗格,管理部分,双击配置编辑器
  4. 在顶部,选择部分 system.webServer/security/authentication/anonymousAuthentication
  5. 右侧窗格,单击解锁部分
  6. 在顶部,选择部分 system.webServer/security/authentication/windowsAuthentication
  7. 右侧窗格,单击解锁部分

  • @PeteStensønes 它有!`&gt;%windir%\system32\inetsrv\appcmd.exe 解锁配置 -section:system.webServer/security/authentication/windowsAuthentication` (4认同)

小智 17

这解决了我在 Windows Server 2012、IIS 8.5 上的错误。也应该适用于其他版本。

  1. 转到服务器管理器,单击添加角色和功能
  2. 在角色部分选择:Web Server
  3. 安全子部分下选择所有内容(我排除了摘要、IP 限制和 URL 授权,因为我们不使用它们)
  4. Application Development 下选择.NET Extensibility 4.5and ASP>NET 4.5,两个 ISAPI 条目
  5. 功能部分选择:NET 3.5, .NET 4.5,ASP.NET 4.5
  6. Web 服务器部分选择:Web Server (all), Management Tools (IIS Management Console and Management Service),Windows


Tri*_*anK 6

配置锁定可能发生在:

  1. Applicationhost.config(配置字符串:MACHINE/WEBROOT/APPHOST)

  2. 站点 Web.config 文件(MACHINE/WEBROOT/APPHOST/网站名称)

  3. 任何应用程序 web.config 文件(机器/WEBROOT/APPHOST/站点名称/应用程序名称)

锁定部分(部分:IIS 配置部分,例如<asp>)可让您拒绝将这些设置配置给层次结构中比您低的任何人。

使用 GUI 的功能委托并没有错,并且与 AppCMD 所做的非常相似,在幕后 -<location>在您关注的任何配置级别的标签中为给定部分设置 OverrideMode 。

APPCMD 可用于解锁文件,但请注意它所说的执行位置 - 在这方面它不如 GUI 聪明。

添加-commit:apphostAPPCMD UNLOCK命令末尾的目标 Applicationhost.config,它是IIS 操作关键文件(替换早期版本的元数据库;存储所有集中设置,但允许在 web.config 文件中覆盖(如果你这样做))。

如果没有 -commit:apphost,APPCMD 将针对 web.config 文件的最接近的逻辑位置 - 无论是在站点级别还是应用程序级别,并使用上述设置的配置字符串指示它已更改设置。(另外:您仍然可以只针对子网站中的设置,但要提交给 apphost - 它使用位置标签来实现这一点)

因此,如果它说(内存释义)“更改已提交给 MACHINE/WEBROOT/APPHOST”,则表示 IIS 层次结构的顶层。

如果它说“提交到 MACHINE/WEBROOT/APPHOST/Dodgy 网站”,那意味着它查找 Dodgy 网站后面的物理路径,并在该位置编写了一个 web.config 文件(或更新了它)。


小智 5

如果您使用的是 IISExpress 和 Visual Studio 2015,applicationHost.config则存储在$(solutionDir).vs\config\applicationhost.config(感谢 Nime Cloud 的回答)。

只需overrideModeDefault="Allow"在适当的地方更改即可。

<sectionGroup name="security">
    <section name="access" overrideModeDefault="Deny" />
    <section name="applicationDependencies" overrideModeDefault="Deny" />
    <sectionGroup name="authentication">
        <section name="anonymousAuthentication" overrideModeDefault="Allow" />
etc...
Run Code Online (Sandbox Code Playgroud)