system.webServer 在 web.config 中的位置

Location of system.webServer within web.config

我正在努力为 ASP.NET 4.51 WebForms 项目寻找 web.config 的明确架构指南。通过各种网络配置,我看到了以下两个,我想知道两者都是正确的,或者确切的区别是什么。

system.webServer 的父节点配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <system.webServer>
   </system.webServer>
</configuration>

或者也可以在位置标签内:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <location>
      <system.webServer>
      </system.webServer>
   </location>
</configuration>

location 元素将引用网站的特定部分,例如,管理位置或其他内容。

例如,以下 web.config 示例会将 <system.webServer> 元素中的任何设置仅应用于站点 /admin 目录中的任何资源:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <location path="~/admin">
        <system.webServer>
            <security>
                <authentication mode="Forms">
                    <forms name=".ASPXFORMS" loginUrl="/admin/logon.aspx" protection="All" path="/admin" timeout="30" />
                </authentication>
            </security>
        </system.webServer>
    </location>
</configuration>

对于应用程序范围 <system.webServer> 设置,提供的第一个示例(没有位置元素)是可行的方法。