Last active
September 3, 2015 13:49
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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