Datasheet

ASP.NET Management Namespace
IIS 7.0 may be configured through the new ASP.NET namespace, Microsoft.Web.Administration,
which is used for administration of IIS web sites and servers. This namespace is an addition to the
ASP.NET framework that is installed with IIS 7.0.
An example of using the
Microsoft.Web.Administration namespace would be the creation of a new
web site. The following C# code sample creates a new site named My New Site with the root at c:\inet-
pub\MyNewSite, running HTTP on port 80:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
namespace MSWebAdmin_Application
{
class Program
{
static void Main(string[] args)
{
ServerManager serverManager = new ServerManager();
serverManager.Sites.Add(“MyNewSite”, “http”, “:80:”,
“c:\\inetpub\\MyNewSite”);
serverManager.Sites[“My New Site”].ServerAutoStart = true;
serverManager.Update();
}
}
}
This would be the same as editing the applicationHost.config file with
<site name=”My New Site” id=”999” serverAutoStart=”true”>
<application path=”/”>
<virtualDirectory path=”/” physicalPath=”c:\inetpub\MyNewSite” />
</application>
<bindings>
<binding protocol=”http” bindingInformation=”:80:” />
</bindings>
</site>
More details and examples of using the Microsoft.Web.Administration namespace appear through-
out the book. You can find the full documentation of the class at
http://msdn2.microsoft.com/en-
us/library/microsoft.web.administration.aspx
.
Windows Management Instrumentation
The classic Windows Management Instrumentation (WMI) is still available in IIS 7.0. All your previous
WMI scripts will work out of the box, and the API has been extended to include all features in IIS 7.0.
The example used in configuring a new web site through the
Microsoft.Web.Administration name-
space would look something like this using WMI:
Set oService = GetObject(“winmgmts:root\WebAdministration”)
22
Part 1: Introduction and Deployment
97823c01.qxd:WroxPro 2/4/08 6:47 PM Page 22