文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>IIS Helper, binding new domain using c#

IIS Helper, binding new domain using c#

时间:2010-09-06  来源:无尽思绪

 

public class IISHelper
{

public static string SiteName
{
get
{
return Config.GetSetting("SiteName");
}
}

public static void AddDomianTmSuite(string portalAlias)
{
using (ServerManager iis = new ServerManager())
{
Site site
= iis.Sites[SiteName];
if (site != null)
{
Binding binding
= GetBinding(site.Bindings, "*:80:" + portalAlias);
if (binding == null)
{
AddBinding(site.Bindings,
"*:80:" + portalAlias);
}
iis.CommitChanges();
}
}
}

public static void DeleteDomainTmSuite(string portalAlias)
{
using (ServerManager iis = new ServerManager())
{
Site site
= iis.Sites[SiteName];
if (site != null)
{
Binding binding
= GetBinding(site.Bindings, "*:80:" + portalAlias);
if (binding != null)
{
site.Bindings.Remove(binding);
}
iis.CommitChanges();
}

}
}

/// <summary>
/// Get Bingding
/// </summary>
/// <param name="bindings">collection of currnet site bindings</param>
/// <param name="BindingInformation">like *:80:asp.google.tst</param>
/// <returns>null or binding</returns>
public static Binding GetBinding(BindingCollection bindings, string BindingInformation)
{
foreach (Binding binding in bindings)
{
if (binding.BindingInformation.ToLower() == BindingInformation.ToLower())
{
return binding;
}
}

return null;
}

/// <summary>
/// Add Binding
/// </summary>
/// <param name="bindings">collection of currnet site bindings</param>
/// <param name="BindingInformation">like *:80:asp.google.tst</param>
public static void AddBinding(BindingCollection bindings, string BindingInformation)
{
Binding binding2
= bindings.CreateElement();
binding2.BindingInformation
= BindingInformation;
binding2.Protocol
= @"http";
bindings.Add(binding2);
}
}

 

官方参考:

http://www.iis.net/ConfigReference/system.applicationHost/sites/site/bindings

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载