Use the Location Element in the Machine.config File
To specify settings that apply to a Web application or
directory, you can add the <location> element to the <configuration> element of a system Machine.config file. This is useful when
you centralize configuration settings in a single file. This is also useful in
Web-hosting environments to mandate specific configuration settings on
individual Web applications.
The <location> element contains two attributes, path and allowOverride. The path
configuration settings cover. To specify that the settings in the <location> element apply to the default Web site, set the path attribute to Default Web Site. To specify that
the settings apply to the application that is named MyApp in
the default Web site, set the path attribute to "Default Web Site/MyApp".
When the allowOverride attribute is false, the Web.config files in the Web application directories cannot
override the settings that you specified in the <location> element. This is a useful setting in environments where you must
restrict application developers in how they configure a Web application. The
following example shows a part of a Machine.config file that requires
authentication to access the MyApp application on the default Web site and that
cannot be overridden by settings in a Web.config file: attribute defines the site or virtual directory that the
<configuration>
<location path=”Default Web Site/MyApp” allowOverride=”false”>
<system.web>
<authorization>
<allow users=”?” />
</authorization>
</system.web>
</location>
</configuration>
Use the Location Element in the Web.config File
To specify settings that apply to a specific application or
directory, add the <location> element to the <configuration> element of an application Web.config file. The <location> element typically contains a <system.web> element and other configuration elements exactly as you use
them in the Web.config file. The path attribute of the <location> element specifies the virtual directory or the file name
where the location configuration items apply. The following example shows part
of an application Web.config file that specifies custom error messages for the
forum virtual directory.
<configuration>
<location path=”forum” >
<system.web>
<customErrors mode="RemoteOnly” defaultRedirect="forum-error.aspx">
<error statusCode="404" redirect="forum-file-not-found.aspx" />
</customErrors>
</system.web>
</location>
</configuration>

0 comments:
Post a Comment