/// <summary> /// Adds a binding to a IIS site /// </summary> /// <param name="settings">The settings of the binding</param> /// <returns>If the binding was added.</returns> public bool AddBinding(string siteName, BindingSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(siteName)) { throw new ArgumentException("Site name cannot be null!"); } //Get Site Site site = _Server.Sites.SingleOrDefault(p => p.Name == siteName); if (site != null) { if (site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation)) != null) { throw new Exception("A binding with the same ip, port and host header already exists."); } //Add Binding Binding newBinding = site.Bindings.CreateElement(); newBinding.Protocol = settings.BindingProtocol.ToString(); newBinding.BindingInformation = settings.BindingInformation; if (settings.CertificateHash != null) { newBinding.CertificateHash = settings.CertificateHash; } if (!String.IsNullOrEmpty(settings.CertificateStoreName)) { newBinding.CertificateStoreName = settings.CertificateStoreName; } site.Bindings.Add(newBinding); _Server.CommitChanges(); _Log.Information("Binding added."); return(true); } else { throw new Exception("Site: " + siteName + " does not exist."); } }
/// <summary> /// Removes a binding to a IIS site /// </summary> /// <param name="siteName">The website name</param> /// <param name="settings">The settings of the binding</param> /// <returns>If the binding was removed.</returns> public bool RemoveBinding(string siteName, BindingSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(siteName)) { throw new ArgumentException("Site name cannot be null!"); } //Get Site Site site = _Server.Sites.SingleOrDefault(p => p.Name == siteName); if (site != null) { Binding binding = site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation)); if (binding != null) { //Remove Binding site.Bindings.Remove(binding); _Server.CommitChanges(); _Log.Information("Binding removed."); return(true); } else { _Log.Information("A binding with the same ip, port and host header does not exists."); return(false); } } else { throw new Exception("Site: " + siteName + " does not exist."); } }
public static void RemoveSiteBinding(this ICakeContext context, string server, BindingSettings settings) { using (ServerManager manager = BaseManager.Connect(server)) { WebsiteManager .Using(context.Environment, context.Log, manager) .RemoveBinding(settings); } }
public static void RemoveSiteBinding(this ICakeContext context, BindingSettings settings) { context.RemoveSiteBinding("", settings); }
public static void RemoveBinding(this ICakeContext context, string server, string siteName, BindingSettings settings) { using (ServerManager manager = BaseManager.Connect(server)) { WebsiteManager .Using(context.Environment, context.Log, manager) .RemoveBinding(siteName, settings); } }
public static void RemoveBinding(this ICakeContext context, string siteName, BindingSettings settings) { context.RemoveBinding("", siteName, settings); }
public bool RemoveBinding(BindingSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(settings.Name)) { throw new ArgumentException("Site name cannot be null!"); } //Get Site Site site = _Server.Sites.SingleOrDefault(p => p.Name == settings.Name); if (site != null) { Binding binding = site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation)); if (binding != null) { //Remove Binding site.Bindings.Remove(binding); _Server.CommitChanges(); _Log.Information("Binding removed."); return true; } else { _Log.Information("A binding with the same ip, port and host header does not exists."); return false; } } else { throw new Exception("Site: " + settings.Name + " does not exist."); } }
public bool AddBinding(BindingSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(settings.Name)) { throw new ArgumentException("Site name cannot be null!"); } //Get Site Site site = _Server.Sites.SingleOrDefault(p => p.Name == settings.Name); if (site != null) { if (site.Bindings.FirstOrDefault(b => (b.Protocol == settings.BindingProtocol.ToString()) && (b.BindingInformation == settings.BindingInformation)) != null) { throw new Exception("A binding with the same ip, port and host header already exists."); } //Add Binding Binding newBinding = site.Bindings.CreateElement(); newBinding.Protocol = settings.BindingProtocol.ToString(); newBinding.BindingInformation = settings.BindingInformation; if (settings.CertificateHash != null) { newBinding.CertificateHash = settings.CertificateHash; } if (!String.IsNullOrEmpty(settings.CertificateStoreName)) { newBinding.CertificateStoreName = settings.CertificateStoreName; } site.Bindings.Add(newBinding); _Server.CommitChanges(); _Log.Information("Binding added."); return true; } else { throw new Exception("Site: " + settings.Name + " does not exist."); } }