Introduction to IIS 7 Management api--microsoft.web.administration

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.