Website installation and packaging creating a website [4] [creating a website]

Source: Internet
Author: User

In the IIS6.0 help document, three program management methods are provided for creating IIS, one is WMI, the other is ADSI, and the other is command line.

Here, we use ADSI programming with a lot of online code.

 

 

 

To use C # For ADSI programming, You need to reference and add the namespace: System. DirectoryServices

Main operation class: DirectoryEntry

The operation content is mainly xml nodes: At this point, it is best to right-click the IIS-website-all tasks-Save the configuration to a file

After saving, view the generated xml content. It is helpful for programming to check the format of the website node.

Enter the code stage

 

Create a website

DirectoryEntry iisEntry = new DirectoryEntry ("IIS: // localhost/w3svc"); // obtain the IIS Node
// Create a website WebSiteID as an integer. You can generate the WebSiteID without repeating it. For more information, see my previous article:
// C # The website cannot be started or stopped when it is created
// Http://www.cnblogs.com/cyq1162/archive/2010/01/09/1642919.html
DirectoryEntry site = (DirectoryEntry) iisEntry. Invoke ("Create", "IIsWebServer", WebSiteID );

Site. Invoke ("Put", "ServerComment", WebSiteName );
Site. Invoke ("Put", "KeyType", "IIsWebServer ");
ArrayList serverBindings = new ArrayList ();
ServerBindings. Add (WebSiteIP + ":" + WebSitePort + ":" + WebSiteDomain );
If (WebSiteIP2! = "" & WebSitePort2! = "")
{
ServerBindings. Add (WebSiteIP2 + ":" + WebSitePort2 + ":" + WebSiteDomain );
}
Site. Invoke ("Put", "ServerBindings", serverBindings. ToArray (); // multiple IP addresses are bound here.
Site. Invoke ("Put", "ServerState", 4); // 4: Stop, 2: Start
Site. Invoke ("Put", "FrontPageWeb", 1 );
Site. Invoke ("Put", "DefaultDoc", "index.html ");
Site. Invoke ("Put", "ServerAutoStart", 0 );
Site. Invoke ("Put", "AuthFlags", 0 );
Site. Invoke ("Put", "ScriptMaps", ScriptArray (). ToArray (); // there are a lot of 2.0 scripts.
Site. Invoke ("Put", "ServerSize", 1 );
Site. Invoke ("SetInfo ");

 

 

After creating a website, you must create a default root node. The Code is as follows:

 

Create Root Node

// Create the Default Root Node directory
DirectoryEntry siteVDir = site. Children. Add ("root", "IISWebVirtualDir ");
SiteVDir. Properties ["AppIsolated"] [0] = 2;
SiteVDir. Properties ["Path"] [0] = WebSitePath;
SiteVDir. Properties ["AccessFlags"] [0] = 513;
SiteVDir. Properties ["FrontPageWeb"] [0] = 1;
SiteVDir. Properties ["AppRoot"] [0] = string. Format ("/LM/W3SVC/{0}/Root", WebSiteID );
SiteVDir. Properties ["AppFriendlyName"] [0] = WebSiteName;
SiteVDir. Properties ["AuthFlags"] [0] = 0;
SiteVDir. Properties ["AccessScript"] [0] = true;
SiteVDir. Properties ["AccessSource"] [0] = true;
SiteVDir. Properties ["DirBrowseFlags"] [0] = 1073741886;
SiteVDir. Properties ["AuthNTLM"] [0] = true; // integrates win authentication.
SiteVDir. Properties ["AuthAnonymous"] [0] = true; // integrates win authentication.
SiteVDir. Properties ["UNCPassword"] [0] = "";
SiteVDir. Properties ["DefaultDoc"] [0] = WebSiteDefaultDoc;

SiteVDir. CommitChanges ();
Site. CommitChanges ();

 

For more information about attributes and meanings, see "reference-> Configure database reference attributes" in the IIS Help document in addition to exporting xml!

After finishing, close the job!

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.