通过代码方式修改IIS主机头
Web技术中文网 2007年7月6日 <script src="/cms-server/ArticleViewTimes.asp?id=101949"></script> 阅读:323次
关键字:
主机头 [GOOGLE搜索更多资料]
转载请注明出处: 只贴代码,相关的描述有空时再补上。
private
void
BindServerBindings(
string
Action,
int
SiteID,
string
vHeader,
string
IPAddress,
int
Port,
string
url)
... { WebSiteInfo _NewWebSiteInfo = new WebSiteInfo(); IISHelperObj = new IISHelper("LOCALHOST"); WebSites website = new WebSites(); IISHelperObj.IsCalculateDirectory = true; website = IISHelperObj.GetWebSites(SiteID); foreach (WebSiteInfo _wsi in website) ...{ ServerBindings _NewServerBinding = new ServerBindings(); ServerBindings sbd = _wsi.ServerBindings; foreach (ServerBinding _sb in sbd) ...{ //删除操作 if (Action == "Delete") ...{ if (_sb.Header == vHeader && _sb.Port == Port) ...{ } else ...{ _NewServerBinding.Add(_sb); } } } _NewWebSiteInfo.WebSiteID = SiteID; _NewWebSiteInfo.ServerBindings = _NewServerBinding; } ServerBindings s = _NewWebSiteInfo.ServerBindings; IISHelperObj.SetWebSite(_NewWebSiteInfo, SiteID, true); Response.Redirect("Succeed.Aspx?Url=" + url); } ServerBinding 类
using
System;
using System.Collections.Generic; using System.Text; using System.Collections; using System.DirectoryServices; namespace JaronSoft.Library.Networks.IIS ... { /**//// <summary> /// 站点绑定 /// 单行值 127.0.0.1:www.jaronsoft.cn:80 /// </summary> [Serializable()] public class ServerBinding ...{ private int _Port = 80; private string _Header; private string _IPAddress = ""; /**//// <summary> /// 端口 /// </summary> public int Port ...{ get ...{ return _Port; } set ...{ _Port = value; } } /**//// <summary> /// 主机头 /// </summary> public string Header ...{ get ...{ return _Header; } set ...{ _Header = value; } } /**//// <summary> /// IP 地址 /// </summary> public string IPAddress ...{ get ...{ return _IPAddress; } set ...{ _IPAddress = value; } } /**//// <summary> /// 得到端口 /// </summary> /// <returns></returns> public int GetPort() ...{ string[] bindings = this.AdsiValue.Split(':'); return int.Parse(bindings[1]); } /**//// <summary> /// 得到主机头 /// </summary> /// <returns></returns> public string GetHeader() ...{ string[] bindings = this.AdsiValue.Split(':'); return bindings[2]; } /**//// <summary> /// 得到IP地址 /// </summary> /// <returns></returns> public string GetIPAddress() ...{ string[] bindings = this.AdsiValue.Split(':'); return bindings[0]; } } /**//// <summary> /// 数据格式 /// (ServerBinding)127.0.0.1:www.jaronsoft.cn:80 /// (ServerBinding)127.0.0.1:iis.jaronsoft.cn:80 /// </summary> [Serializable()] public class ServerBindings : CollectionBase ...{ /**//// <summary> /// this /// </summary> /// <param name="index"></param> /// <returns></returns> public ServerBinding this[int index] ...{ get ...{ return ((ServerBinding)List[index]); } set ...{ List[index] = value; } } /**//// <summary> /// 添加 /// </summary> /// <param name="value"></param> /// <returns></returns> public void Add(ServerBinding value) ...{ List.Add(value); } /**//// <summary> /// 索引 /// </summary> /// <param name="index"></param> /// <returns></returns> public ServerBinding IndexOf(int index) ...{ return (ServerBinding)List[index]; } /**//// <summary> /// 删除 /// </summary> /// <param name="value"></param> public void Remove(ServerBinding value) ...{ List.Remove(value); } } } 更新
处理主机头绑定
#region 处理主机头绑定
Object[] newList = new Object[newSiteInfo.ServerBindings.Count]; for (int i = 0; i < newSiteInfo.ServerBindings.Count; i++) ...{ string headerStr = string.Format("{0}:{1}:{2}", newSiteInfo.ServerBindings[i].IPAddress, newSiteInfo.ServerBindings[i].Port, newSiteInfo.ServerBindings[i].Header); newList[i] = headerStr; } newSiteEntry.Properties["ServerBindings"].Value = newList; #endregion | ||
参与讨论(本站原创作品可提供技术支持) 涉及版权问题或文档错误请与管理员联系 | ||
| ||
相关连接:
|
通过代码方式修改IIS主机头
最新推荐文章于 2021-03-19 16:00:29 发布