Original: http://www.cnblogs.com/dflying/archive/2006/04/17/377276.html
This article translates the blog post from Carlos Aguilar Mares: Microsoft.Web.Administration in IIS 7.
Please note that this article is based on the Windows Vista Beta 2 release and may change in the official release version.
Some of the very powerful api--Microsoft.Web.Administrationfor managing IIS7 are available in Microsoft, which makes it easy for us to programmatically manage the configuration of IIS 7. Microsoft.Web.Administration.dll is located in the IIS directory (%WINDIR%\SYSTEM32\INETSRV), you can use these APIs after you add references to them in your project. Shows the main objects in the Microsoft.Web.Administration.dll.
Let's take a few examples to use Microsoft.Web.Administration, the following examples are very easy to understand, I will no longer explain too much.
Establish a site
Servermanager Iismanager= NewServermanager ();
IISMANAGER.SITES.ADD ("NewSite", "http", "*:8080:", "D:\\mysite");
Iismanager.update ();
Add an application (application) to a site
Servermanager Iismanager= NewServermanager ();
iismanager.sites["NewSite"]. Applications.add ("/sales", "D:\\myapp");
Iismanager.update ();
Create a virtual directory ( Virtual Directory)
Servermanager Iismanager= NewServermanager ();
Application App=iismanager.sites["NewSite"]. applications["/sales"];
App. Virtualdirectories.add ("/vdir", "D:\\myvdir");
Iismanager.update ();
Run-time Control: Stop a site
Servermanager Iismanager= NewServermanager ();
iismanager.sites["NewSite"]. Stop ();
run-Time Control: Recycle Application pools ( recyciling an application Pool)
Servermanager Iismanager= NewServermanager ();
iismanager.applicationpools["DefaultAppPool"]. Recycle ();
Run-time control: Get the request that is currently being processed
Servermanager Iismanager= NewServermanager ();
foreach(workerprocess w3wpinchiismanager.workerprocesses) {
Console.WriteLine ("w3wp ({0})", w3wp. PROCESSID);
foreach(Request requestinchw3wp. Getrequests (0)) {
Console.WriteLine ("{0}-{1},{2},{3}",
Request. Url
Request. CLIENTIPADDR,
Request. Timeelapsed,
Request. Timeinstate);
}
}
Another useful feature of the
is that Microsoft.Web.Administration provides the ability to edit *.config (for example, Web. config) files so that you no longer have to modify *.config as you would any normal XML file. But the original author said he would explain it in detail in the next post, and I'll just write about it here.