Skip to content

Instantly share code, notes, and snippets.

@vince-geekcore
Last active September 3, 2015 13:49
Show Gist options
  • Save vince-geekcore/2dc237077cdd6117371a to your computer and use it in GitHub Desktop.
Save vince-geekcore/2dc237077cdd6117371a to your computer and use it in GitHub Desktop.
Create an IIS binding using the MS ServerManager (Microsoft.Web.Administration namespace)
/// <summary>
/// Create an IIS binding. Warning: Sitecore will pickup the IIS
/// change and will restart when this code is executed!
/// </summary>
/// <returns></returns>
public void CreateIISBinding()
{
ServerManager iisManager = new ServerManager();
Site site = iisManager.Sites[Properties.Settings.Default.IISInstanceName];
string binding = string.Format(@"{0}:{1}:{2}", "*", "80", this.HostName);
Binding siteBinding = site.Bindings.Where(x => x.BindingInformation == binding).FirstOrDefault();
if (siteBinding != null)
{
throw new InvalidOperationException("IIS Binding already exists");
}
site.Bindings.Add(binding, "http");
iisManager.CommitChanges();
this.IsIISbindingSet = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment