////http:*:80:www.abcdefg.com ////https:*:443:www.abcdefg.com::CertStoreName\\a03083aabcd6bdfec92214df7e885c9e1e1a864d public override void SetBindings(String siteBindings) { //We need to parse the bindings string IISBindingParser.Parse(siteBindings, delegate(IISBinding iisBinding) { Binding binding = site.Bindings.FirstOrDefault <Binding>(t => t.BindingInformation.Equals(iisBinding.SMBindString, StringComparison.CurrentCultureIgnoreCase)); if (binding != null) { site.Bindings.Remove(binding); } binding = site.Bindings.CreateElement("binding"); binding.Protocol = iisBinding.Protocol; binding.BindingInformation = iisBinding.SMBindString; if ((iisBinding.CertificateHash != "") && iisBinding.Protocol.Equals("https", StringComparison.CurrentCultureIgnoreCase)) { binding.CertificateHash = SSLCertificates.HexStringToByteArray(iisBinding.CertificateHash); binding.CertificateStoreName = iisBinding.CertificateStore; if (IIS.Version.ProductMajorPart >= 8) { binding.SetAttributeValue("sslFlags", 1); // Enable SNI support } } site.Bindings.Add(binding); }); CommitServerManagerChanges(); }
//http::80:www.abcdefg.com //https::443:www.abcdefg.com public override void SetBindings(String siteBindings) { DirectoryEntry webServer = new DirectoryEntry(String.Format("IIS://localhost/w3svc/{0}", SiteId)); //We need to parse the bindings string webServer.Properties["ServerBindings"].Clear(); IISBindingParser.Parse(siteBindings, delegate(IISBinding iisBinding) { if (iisBinding.Protocol.Equals("http", StringComparison.CurrentCultureIgnoreCase)) { webServer.Properties["ServerBindings"].Add(iisBinding.WMIBindString); } }); webServer.Properties["SecureBindings"].Clear(); IISBindingParser.Parse(siteBindings, delegate(IISBinding iisBinding) { if (iisBinding.Protocol.Equals("https", StringComparison.CurrentCultureIgnoreCase)) { webServer.Properties["SecureBindings"].Add(iisBinding.WMIBindString); } }); webServer.CommitChanges(); }