配置特定文件和子目录

更新:2007 年 11 月

通过使用具有适当的 path 属性的 <location> 标记,可以将配置设置应用于特定的资源。path 属性可用于标识要应用唯一配置设置的特定文件或子目录。在 path 属性中只能使用一个文件路径。path 属性可以从指示应用程序根目录的“~/”快捷方式开头。有关更多信息,请参见 ASP.NET 网站路径

例如,下面的示例配置文件在三个级别指定设置:

  • 应用于当前目录和所有子目录的设置(全部内容包含在顶部 <configuration> 标记中)。

  • 应用于 Sub1 子目录的设置(全部内容都包含在路径属性设置为 Sub1 的 <location> 标记中)。

  • 应用于 Sub2 子目录的设置(全部内容都包含在路径属性设置为 Sub2 的 <location> 标记中)。

<configuration>
  <system.web>
    <sessionState cookieless="true" timeout="10"/>
  </system.web>
         
  <!-- Configuration for the "sub1" subdirectory. -->
  <location path="sub1">
    <system.web>
      <httpHandlers>
        <add verb="*" path="sub1" type="Type1"/>
        <add verb="*" path="sub1" type="Type2"/>
      </httpHandlers>
    </system.web>
  </location>
   
  <!-- Configuration for the "sub1/sub2" subdirectory. -->
  <location path="sub1/sub2">
    <system.web>
      <httpHandlers>
        <add verb="*" path="sub1/sub2" type="Type3"/>
        <add verb="*" path="sub1/sub2" type="Type4"/>
      </httpHandlers>
    </system.web>
  </location>
</configuration>

请参见

任务

如何:使用位置设置配置特定目录

其他资源

管理 ASP.NET 网站

配置应用程序