Share via


設定特定的檔案和子目錄

更新:2007 年 11 月

您可以使用含有適當 path 屬性 (Attribute) 的 <location> 標記,將組態設定套用至特定的資源。path 屬性可用來識別唯一組態設定的特定檔案或子目錄。path 屬性中只能使用一個檔案路徑。path 可以用 "~/" 捷徑做開頭,因為這個捷徑會指定應用程式的根目錄。如需詳細資訊,請參閱 ASP.NET 網站路徑

例如,下列組態檔範例指定三種層級的設定:

  • 套用至目前目錄和所有子目錄的設定 (最上層的 <configuration> 標記包含的所有內容)。

  • 套用至 Sub1 子目錄的設定 (<location> 標記包含的所有內容,其路徑屬性設定為 Sub1)。

  • 套用至 Sub2 子目錄的設定 (<location> 標記包含的所有內容,其路徑屬性設定為 Sub2)。

<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>

請參閱

工作

HOW TO:使用位置設定設定特定的目錄

其他資源

管理 ASP.NET 網站

設定應用程式