Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7,C#
Expertise: Intermediate
Aug 24, 2002

Centralize ASP.NET settings in one file

Although ASP.NET lets you distribute web.config files over all the application's subdirectories, it surely doesn't force you to do so. You can keep all the application settings in its main web.config file, while enforcing different settings on a directory-by-directory base, if you want. The key to this useful feature is the tag.

For example, let's see how an application's configuration file can specify different authorization settings for its different subdirectories. This web.config file enforces the same settings as the example seen in previous section:

<configuration>
  <system.web>
    <authorization>
      <allow roles="MyDomain\Administrator" />
      <deny users="*" />
    </authorization>
  </system.web>

  <location path="/Public">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>
</configuration>
You can use a tag also in machine.config to affect settings in individual ASP.NET applications and their subdirectories. In this case, the path attribute must begin with the IIS site name, as read in the MMC snap-in. For example, here's how you can enable tracing for the .aspx files in the /MyApp virtual directory of the default Web site:
<location path="Default Web Site/MyApp">
  <system.web>
    <trace enabled="true" localOnly="true" pageOutput="true" />
  </system.web>
</location>


This tips has been taken from Chapter 24 "ASP.NET Applications" of Francesco Balena's Programming Microsoft Visual Basic .NET (Microsoft Press). Read a sample chapter from our Book Bank, or buy at 30% off the list price.
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap