C # reads the site-related property code in IIS

Source: Internet
Author: User
Tags foreach iis tostring
iis| site

private void ComboBox1_SelectedIndexChanged (object sender, System.EventArgs e)
{
String currentservercomment=combobox1.selecteditem.tostring ();
String currentsitenum = Getwebsitenum (currentservercomment);
String rootpath = "Iis://localhost/w3svc";
String Currentsitepath =rootpath+ "/" +currentsitenum;
DirectoryEntry siteentry = new DirectoryEntry (Currentsitepath);

   string currentserverbindings=siteentry.properties["ServerBindings"]. Value.tostring ();
   char[] a= ":". ToCharArray ();
   string [] currentbingdings = null;   
   currentbingdings= Currentserverbindings.split (a);
   string Currentserverip=currentbingdings[0];
   string currentserverport=currentbingdings[1];
   string currentserverheader=currentbingdings[2];
   string currentserverhost= "";
   string currentserverpath= "";

foreach (DirectoryEntry Child in Siteentry.children)
{

if (child. schemaClassName = = "IIsWebVirtualDir") && (child. name== "root"))
{
Currentserverpath = child. properties["Path"]. Value.tostring ();

}
}

Textbox2.text=currentserverip;
Textbox3.text=currentserverport;
Textbox4.text=currentserverpath;
Textbox5.text=currentserverheader;
Textbox6.text=currentserverhost;
}

<summary>
Get the site identifier based on the site name
</summary>

public string Getwebsitenum (string siteName)
{

Regex regex = new Regex (siteName);
String tmpstr;
String Entpath = "Iis://localhost/w3svc";
DirectoryEntry Ent =new DirectoryEntry (Entpath);

foreach (DirectoryEntry Child in Ent.) Children)

{
if (child. schemaClassName = = "IIsWebServer")
{
if (child. properties["ServerBindings"]. Value!= null)
{
TMPSTR = child. properties["ServerBindings"]. Value.tostring ();
if (regex). Match (TMPSTR). Success)
{
Return to child. Name;
}
}

if (child. properties["ServerComment"]. Value!= null)

{
TMPSTR = child. properties["ServerComment"]. Value.tostring ();
if (regex). Match (TMPSTR). Success)
{
Return to child. Name;
}
}
}
}
Return "";

}



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.