static void addhostheader(int siteid,string ip, int port, string domain)
{
directoryentry site = new directoryentry("iis://localhost/w3svc/"+siteid);
propertyvaluecollection serverbindings = site.properties["serverbindings"];
string headerstr = string.format("{0}:{1}:{2}",ip,port,domain);
if (!serverbindings.contains(headerstr))
{
serverbindings.add(headerstr);
}
site.commitchanges();
}
在找到append a host header by code in iis之前,我通過(guò)下面的代碼沒(méi)找到"serverbindings"屬性,走了一些彎路。
directoryentry site = new directoryentry("iis://localhost/w3svc/1/root");
代碼很簡(jiǎn)單,需要說(shuō)明的是siteid,默認(rèn)站點(diǎn)是1,對(duì)于非默認(rèn)站點(diǎn),通過(guò)查看站點(diǎn)日志文件名就可以知道。
|
新聞熱點(diǎn)
疑難解答
圖片精選