Operating IIS 7.0 in C #

Source: Internet
Author: User
Tags iis new features

Microsoft has published IIS 7.0 with Windows Vista, which is the topic of last year, and then the Web programs developed by. NET are gradually transitioning from IIS 6.0 to IIS 7.0. IIS 7.0 offers a number of new features that are more than the previous version, including fully modular components, the configuration of text files, MMC graphics-mode management tools, and so on. NET programming languages, the new Microsoft.Web.Administration namespaces also add a lot of objects to manage and access IIS, making it easier to programmatically manipulate IIS. Although it is easy to manage IIS for the server through C # in the IIS 6.0 era, there are fewer code to write and more functionality to do. The following is part of a class library that I wrote in a project I used to do, primarily to implement IIS 7.0, including creating and deleting sites, creating and deleting virtual directories, creating and deleting application pools, adding site default documents, determining whether sites and virtual directories exist, and check bindings information.

For the introduction of IIS 7.0 readers who are interested can look at the following two articles, I feel good!

Http://blog.joycode.com/scottgu/archive/2007/04/08/100650.aspx

Http://msdn.microsoft.com/en-us/magazine/cc163453.aspx

Don't talk nonsense, hurry up and paste code.

The first is the management of the site. I wrote a relatively generic private approach, and then gave the calling interface in the external approach, including the creation of the application pool and the administration of permissions when the site was created.

CreateSite

<summary>
Create a new web site.
</summary>
<param name= "SiteName" ></param>
<param name= "Bindinginfo" > "*:&lt;port&gt;:&lt;hostname&gt;" <example> "*:80: Myhost.com "</example></param>
<param name= "PhysicalPath" ></param>
public static void CreateSite (String siteName, String bindinginfo, String physicalpath)
{
CreateSite (siteName, "http", Bindinginfo, PhysicalPath, True, SiteName + "Pool", Processmodelidentitytype.networkservice, NULL, NULL, managedpipelinemode.integrated, NULL);
}

private static void CreateSite (String siteName, String protocol, String bindinginformation, String PhysicalPath,
BOOL Createapppool, String apppoolname, Processmodelidentitytype identitytype,
String Apppoolusername, String Apppoolpassword, Managedpipelinemode apppoolpipelinemode, String managedruntimeversion )
{
using (Servermanager mgr = new Servermanager ())
{
Site site = Mgr. Sites.add (siteName, Protocol, bindinginformation, PhysicalPath);

Provision AppPool IF NEEDED
if (Createapppool)
{
ApplicationPool pool = Mgr. Applicationpools.add (AppPoolName);
if (pool. Processmodel.identitytype!= Identitytype)
{
Pool. Processmodel.identitytype = Identitytype;
}
if (! String.IsNullOrEmpty (Apppoolusername))
{
Pool. Processmodel.username = Apppoolusername;
Pool. Processmodel.password = Apppoolpassword;
}
if (Apppoolpipelinemode!= pool. Managedpipelinemode)
{
Pool. Managedpipelinemode = Apppoolpipelinemode;
}

Site. applications["/"]. Applicationpoolname = pool. Name;
}

Mgr.commitchanges ();
}
}

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.