Advanced Ajapa Yoga Kriyas and Meditations for Software Developers : Tap the power of breath, mantra, mudra, and dhyana for improved focus, peace of mind, and blissful inner connection.


Getting Started with IIS7 (Part 2)

Introduction

In the Part 1 of this series you learnt the common tasks such as application pool management, web site creation and IIS application creation. In this part I will discuss about the hierarchical configuration system used by IIS7 along with feature delegation.

IIS7 Configuration

In the previous versions of IIS the configuration used to reside in what is known as IIS metabase. The metabase file was a binary file under IIS 5.x and an XML file under IIS6. Still it was a sort of monolithic with very little control. The IIS7 provides a whole new configuration model that is much more flexible and allows for configuration inheritance and overriding easily.

All the IIS metabase information is now stored in a file named applicationHost.config. This file resides in \Windows\System32\InetSrv\config folder. This file contains a list of all websites and IIS applications configured under your web server. Have a look at the markup below (unwanted markup removed for better readability):

<system.applicationHost>
  <applicationPools>
    <add name="MyNewPool" autoStart="true" />
  </applicationPools>
  <sites>
    <site name="MyWebSite" id="2">
      <application path="/">
        <virtualDirectory path="/" 
              physicalPath="D:\Bipin\Test" />
        <virtualDirectory path="/MyVirDir" 
              physicalPath="D:\Bipin\Test\TestVirDir" />
      </application>
      <application path="/MyWebApp">
        <virtualDirectory path="/" 
              physicalPath="D:\Bipin\Test\TestApp" />
      </application>
      <bindings>
        <binding protocol="http" 
          bindingInformation="*:8088:" />
      </bindings>
    </site>
  </sites>
</system.applicationHost>

The <system.applicationHost> section stores the information about IIS websites. The <applicationPools> section stores information about application pools whereas <sites> section stores information about web sites, IIS applications and Virtual Directories.

The applicationHost.config file also stores default settings for web sites and virtual directories under <system.webServer> section (see below).

<system.webServer>
<caching enabled="true" enableKernelCache="true">
</caching>
<defaultDocument enabled="true">
<files>
  <add value="Default.htm" />
  <add value="Default.asp" />
  <add value="index.htm" />
  <add value="index.html" />
  <add value="iisstart.htm" />
  <add value="default.aspx" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />
...
</system.webServer> 

One interesting fact about the applicationHost.config file is that it is based on the same model as web.config files. This means you can use web.config of an IIS application to override settings from the applicationHost.config file.

Ok. Now that you know how IIS7 stores its configuration, let's understand how ASP.NET related configuration is inherited and overridden. 

Inheriting and Overriding ASP.NET Configuration

The mechanism of configuration inheritance and overriding can be best understood with an example. Open IIS manager and select the root web site. Locate "Application Settings" option from the Workspace pane and add a new key-value pair as shown below:

Where does this configuration gets stored? Locate \Windows\Microsoft .NET\Framework\<version>\Config folder. There you will find a web.config file. If you open it in Notepad you will see an <appSettings> section as shown below:

<appSettings>
  <add key="Key1" value="Value1" />
</appSettings>

Now, select MyWebSite web site under Web Sites folder (recollect that we created MyWebSite in the Part 1 of this series). Locate Application Settings option under Workspace pane. If you double click on it you will find a key with name key1 automatically listed.

This means the settings from the root web site got inherited in the child web site.

Now, double click on Key1 from the child web site and change the value to ValueNew. Navigate to the physical folder of MyWebSite. There you will find a web.config file with the following markup.

<appSettings>
  <remove key="Key1" />
  <add key="Key1" value="ValueNew" />
</appSettings>

As you can see the child web.config file overrides the Key1 setting of the parent web.config. The same inheritance and overriding concept is applicable for MyWebSite and MyWebApp.

Feature Delegation

As discussed above IIS7 allows developers to override sections from applicationHost.config from web.config file. However, what if you want to prohibit this behavior? Luckly, IIS7 provides what is known as Feature Delegation that allows you to control this aspect.

Select the root web site under Connections pane. Then double click on Feature Delegation under Workspace pane to open Feature Delegation section as shown below:

As you can see the Feature Delegation section lists all the features that can be configured. The Actions pane contains options to control the operation that can be performed on them (Read Only, Read and Write etc.). Click on "Read Only" to mark this section as a read only section i.e. child web sites cannot override it.

Next, navigate to MyWebSite and double click on Application Settings. This time you will get an error as shown below:

Ok. That's it! To summarize we can conclude that the IIS7 architecture and features are more flexible and powerful than its previous versions.


Bipin Joshi is an independent software consultant and trainer by profession specializing in Microsoft web development technologies. Having embraced the Yoga way of life he is also a meditation teacher and spiritual guide to his students. He is a prolific author and writes regularly about software development and yoga on his websites. He is programming, meditating, writing, and teaching for over 27 years. To know more about his ASP.NET online courses go here. More details about his Ajapa Japa and Shambhavi Mudra online course are available here.

Posted On : 29 June 2008







Advanced Ajapa Yoga Kriyas and Meditations for Software Developers : Tap the power of breath, mantra, mudra, and dhyana for improved focus, peace of mind, and blissful inner connection.