Пример #1
0
        public bool AddSiteBinding(string name, KuduBinding binding)
        {
            var application = GetApplication(name);
            if (application == null)
            {
                return false;
            }

            return _siteManager.AddSiteBinding(name, binding);
        }
Пример #2
0
        public bool AddSiteBinding(string applicationName, KuduBinding binding)
        {
            try
            {
                using (ServerManager iis = GetServerManager())
                {
                    if (!IsAvailable(binding.Host, binding.Port, iis))
                    {
                        return(false);
                    }

                    IIS.Site site = binding.SiteType == SiteType.Live
                        ? iis.Sites[GetLiveSite(applicationName)]
                        : iis.Sites[GetServiceSite(applicationName)];

                    if (site == null)
                    {
                        return(true);
                    }

                    string bindingInformation = string.Format("{0}:{1}:{2}", binding.Ip, binding.Port, binding.Host);
                    switch (binding.Schema)
                    {
                    case UriScheme.Http:
                        site.Bindings.Add(bindingInformation, "http");
                        break;

                    case UriScheme.Https:
                        Certificate cert = _certificateSearcher.Lookup(binding.Certificate).ByThumbprint();
                        Binding     bind = site.Bindings.Add(bindingInformation, cert.GetCertHash(), cert.StoreName);
                        if (binding.Sni)
                        {
                            bind.SetAttributeValue("sslFlags", SslFlags.Sni);
                        }

                        break;
                    }
                    iis.CommitChanges();
                    Thread.Sleep(1000);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(false);
            }
        }
Пример #3
0
        private KuduBinding MapBinding(Binding binding)
        {
            KuduBinding kuduBinding = new KuduBinding();

            kuduBinding.Host   = binding.Host;
            kuduBinding.Scheme = binding.Protocol.Equals("http", StringComparison.OrdinalIgnoreCase) ? UriScheme.Http : UriScheme.Https;
            kuduBinding.Port   = binding.EndPoint.Port;
            kuduBinding.Ip     = binding.EndPoint.Address.ToString();

            //NOTE: A KuduBinding also has information about certificate name etc...
            //      and SNI which we could try and fetch...

            //Extra for making target URLS.
            kuduBinding.DnsName = _context.HostName;
            return(kuduBinding);
        }
Пример #4
0
        public bool RemoveSiteBinding(string applicationName, KuduBinding siteBinding, SiteType siteType)
        {
            try
            {
                using (ServerManager iis = GetServerManager())
                {
                    IIS.Site site = siteType == SiteType.Live
                        ? iis.Sites[GetLiveSite(applicationName)]
                        : iis.Sites[GetServiceSite(applicationName)];

                    if (site == null)
                    {
                        return(true);
                    }

                    Binding binding = site.Bindings
                                      .FirstOrDefault(x => x.Host.Equals(siteBinding.Host) &&
                                                      x.EndPoint.Port.Equals(siteBinding.Port) &&
                                                      x.EndPoint.Address.ToString() == siteBinding.Ip &&
                                                      x.Protocol.Equals(siteBinding.Scheme.ToString(), StringComparison.OrdinalIgnoreCase));

                    if (binding == null)
                    {
                        return(true);
                    }

                    site.Bindings.Remove(binding);
                    iis.CommitChanges();
                    Thread.Sleep(1000);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(false);
            }
        }
Пример #5
0
        public bool AddSiteBinding(string applicationName, KuduBinding binding)
        {
            try
            {
                using (ServerManager iis = GetServerManager())
                {
                    if (!IsAvailable(binding.Host, binding.Port, iis))
                    {
                        return false;
                    }

                    IIS.Site site = binding.SiteType == SiteType.Live
                        ? iis.Sites[GetLiveSite(applicationName)]
                        : iis.Sites[GetServiceSite(applicationName)];

                    if (site == null)
                    {
                        return true;
                    }

                    string bindingInformation = string.Format("{0}:{1}:{2}", binding.Ip, binding.Port, binding.Host);
                    switch (binding.Schema)
                    {
                        case UriScheme.Http:
                            site.Bindings.Add(bindingInformation, "http");
                            break;

                        case UriScheme.Https:
                            Certificate cert = _certificateSearcher.Lookup(binding.Certificate).ByThumbprint();
                            Binding bind = site.Bindings.Add(bindingInformation, cert.GetCertHash(), cert.StoreName);
                            if (binding.Sni)
                            {
                                bind.SetAttributeValue("sslFlags", SslFlags.Sni);
                            }

                            break;
                    }
                    iis.CommitChanges();
                    Thread.Sleep(1000);
                }
                return true;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return false;
            }
        }