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之前,我通过下面的代码没找到"serverbindings"属性,走了一些弯路。
directoryentry site = new directoryentry("iis://localhost/w3svc/1/root");
代码很简单,需要说明的是siteid,默认站点是1,对于非默认站点,通过查看站点日志文件名就可以知道。
新闻热点
疑难解答
图片精选