ASP. NET iis7 Management

Source: Internet
Author: User

The old program manages IIS6 and cannot be used after the server updates iis7.

Introduction http://dflying.cnblogs.com/archive/2006/04/17/377276.html to this address found online

However, the above Code cannot be generated.

Servermanager iismanager = new servermanager ();
Iismanager. sites. Add ("newsite", "HTTP", "*: 8080:", "d: \ mysite ");
Iismanager. Update ();

 

No update method is displayed.

 

After querying msdn, find the solution and debug it successfully.

 

/// <Summary>
/// Iis7 create a website
/// </Summary>
/// <Param name = "name"> website name </param>
/// <Param name = "Port"> port </param>
/// <Param name = "Domain"> bind a domain name </param>
Public void createsitebyname (string name, string port, string domain)
{
String Path = @ "C: \ WEB \" + name + "Site ";

// Validate the site name
Char [] invalid = sitecollection. invalidsitenamecharacters ();
If (name. indexofany (invalid)>-1)
{
Console. writeline ("invalid site name: {0}", name );
}

// Create the content directory if it doesn't exist.
If (! System. Io. Directory. exists (PATH ))
{
System. Io. Directory. createdirectory (PATH );
}

// Create a new site using the new directory and update the config
Servermanager manager = new servermanager ();
Try
{// Add this site.

Site hrsite = manager. sites. Add (name, "HTTP", "*:" + port + ":" + domain, PATH );
Hrsite. serverautostart = true;
Manager. commitchanges ();
Console. writeline ("Site" + name + "added to applicationhost. config file .");
}
Catch
{
}
}

 

 

 

When the program is released, it is displayed that it has no permissions. You must add the network service user permission to c: \ windows \ system32 \ inetsrv \ config.

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.