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 "";
}