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>
/// 根据站点名称获取站点标识符
/// </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 child.name;
}
}
if(child.properties["servercomment"].value != null)
{
tmpstr = child.properties["servercomment"].value.tostring();
if(regex.match(tmpstr).success)
{
return child.name;
}
}
}
}
return "";
}
新闻热点
疑难解答
图片精选