Example #1
0
        ////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();
        }
Example #2
0
        public static IISSite FindSite(IISIdentifier Identifier)
        {
            IISServerManagerSite retVal = new IISServerManagerSite();

            if (Identifier is IISBindingIdentifier)
            {
                List <IISBinding> bindings = IISBindingParser.ParseToList(Identifier.Value);

                foreach (Site iisSite in retVal.ServerMgr.Sites)
                {
                    if (retVal.site != null)
                    {
                        break;
                    }
                    foreach (IISBinding query in bindings)
                    {
                        if (retVal.site != null)
                        {
                            break;
                        }
                        if (iisSite.Bindings.FirstOrDefault <Binding>(b => b.BindingInformation.Equals(query.SMBindString)) != null)
                        {
                            retVal.site = iisSite;
                        }
                    }
                }
            }
            else
            {
                retVal.site = retVal.ServerMgr.Sites[Identifier.Value];
            }
            //Return null if the site was not found
            return((retVal.site != null) ? retVal : null);
        }
Example #3
0
        //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();
        }