Share via


How to: Configure Specific Directories Using Location Settings 

By using the ___location element with an appropriate value for the path attribute, you can apply configuration settings to specific folders and files. The path attribute can be used to identify a specific file or child directory to which unique configuration settings apply. Only one file path can be used in the path attribute. The ___location element takes precedence over any ASP.NET configuration setting in the current Web.config file.

You can set the ___location element programmatically by using the ASP.NET configuration API, or you can set it by using the Locations tab in the ASP.NET MMC snap-in.

The default value for the Path property is ".". Multiple ___location elements can exist in the same configuration file, specifying different scopes for the same configuration sections, as in the following example:

  <___location path="." >
    <section1 … />
    <section2 … />
  </___location>
  <___location path="Default Web Site" >
    <section1 … />
    <section2 … />
  </___location
  <___location path="Default Web Site/foo/bar/xyz.html" >
    <section1 … />
    <section2 … />
  </___location>

Example

The following code example shows a configuration file that specifies settings for two specific resources:

  • Settings that apply only to the Sub1 child directory are between the <___location> and </___location> tags, with a path attribute set to Sub1.

  • Settings that apply only to the Sub2 child directory are between the <___location> and </___location> tags, with a path attribute set to Sub1.

Settings that apply to the current directory and all child directories are between the <configuration> and </configuration> tags, but they are not enclosed by the <___location> and </___location> tags.

<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.Scott" type="Sub1.Scott" />
        <add verb="*" path="Sub1.David" type="Sub1.David" />
      </httpHandlers>
    </system.web>
  </___location>

  <!-- Configuration for the "Sub2" subdirectory. -->
  <___location path="sub2">
    <system.web>
      <httpHandlers>
        <add verb="*" path="Sub2.Scott" type="Sub2.Scott" />
        <add verb="*" path="Sub2.David" type="Sub2.David" />
      </httpHandlers>
    </system.web>
  </___location>
</configuration>

See Also

Tasks

How to: Lock ASP.NET Configuration Settings

Other Resources

ASP.NET MMC Snap-In