Welcome to Bilal Haidar [MVP, MCT] Official Blog Sign in | Join | Help

Microsoft.Web.Administration API

In IIS 7.0, you can use one the following 4 ways to configure the IIS 7.0 settings configuration system:

  1. IIS 7.0 Manager tool.
  2. appcmd.exe command-line tool.
  3. Microsoft.Web.Administration managed API.
  4. Manual editing for the ApplicationHost.config file.

In this post I will introduce the Microsoft.Web.Administration API. The IIS 7.0 team thought of the developers and provided this managed API that allows you to access the configuration system of the IIS 7.0. The API get loaded into the machince once you install IIS and it is located at: %SystemDrive%\Windows\System32\Inetsrv\.

The major object in the API is the ServerManager class. It is a factory class that contains several important properties like the Sites, ApplicationPools, VirtualDirectories, etc .... For example, to create a new website on II 7.0, you can write the following:

            // Get a reference to the factory object
            // ServerManager
            var manager = new ServerManager();

            // Define a new website
            manager.Sites.Add(
                "ProgrammaticSite",
                @"D:\ProgrammaticSite\",
                8080);

            // Commit changes to the ApplicationHost.config
            manager.CommitChanges();

That's it!!

For a more detailed reference on the API, you can check the following article How to Use Microsoft.Web.Administration (http://learn.iis.net/page.aspx/165/how-to-use-microsoftwebadministration/)

Hope this helps,
Regards

 

Published Sunday, March 02, 2008 8:59 PM by BilalHaidar [MVP]

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required)