通过代码方式修改IIS主机头

通过代码方式修改IIS主机头
Web技术中文网 2007年7月6日 <script src="/cms-server/ArticleViewTimes.asp?id=101949"></script> 阅读:323次
 

转载请注明出处:
原创作者: Jaron , CSDN IIS技术版主 2007/3/26
- CSDN
- 佳融软件

只贴代码,相关的描述有空时再补上。

     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

参与讨论(本站原创作品可提供技术支持) 涉及版权问题或文档错误请与管理员联系

相关连接:
如何为自己的网站设置二级域名?2004年8月3日
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值