IIS Helper, binding new domain using c #

Source: Internet
Author: User

 

 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);
}
}

 

Official reference:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.