public ActionResult Hostname(string id)
        {
            var settings = new AppSettingsAuthConfig();
            var model    = new HostnameModel();
            List <ValidationResult> validationResult = null;

            if (settings.IsValid(out validationResult))
            {
                var client = ArmHelper.GetWebSiteManagementClient(settings);

                var site = client.Sites.GetSiteOrSlot(settings.ResourceGroupName, settings.WebAppName, settings.SiteSlotName);
                model.HostNames         = site.HostNames;
                model.HostNameSslStates = site.HostNameSslStates;
                model.Certificates      = client.Certificates.GetCertificates(settings.ServicePlanResourceGroupName).Value;
                model.InstalledCertificateThumbprint = id;
                if (model.HostNames.Count == 1)
                {
                    model.ErrorMessage = "No custom host names registered. At least one custom domain name must be registed for the web site to request a letsencrypt certificate.";
                }
            }
            else
            {
                var errorMessage = string.Join(" ,", validationResult.Select(s => s.ErrorMessage));
                model.ErrorMessage = $"Application settings was invalid, please wait a little and try to reload page if you just updated appsettings. Validation errors: {errorMessage}";
            }

            return(View(model));
        }
        private void SetViewBagHostnames()
        {
            var settings = new AppSettingsAuthConfig();
            var client   = ArmHelper.GetWebSiteManagementClient(settings);

            var site  = client.Sites.GetSiteOrSlot(settings.ResourceGroupName, settings.WebAppName, settings.SiteSlotName);
            var model = new HostnameModel();

            ViewBag.HostNames = site.HostNames.Where(s => !s.EndsWith(settings.AzureWebSitesDefaultDomainName)).Select(s => new SelectListItem()
            {
                Text  = s,
                Value = s
            });
        }
Ejemplo n.º 3
0
        public ActionResult Hostname(string id)
        {
            var settings = new AppSettingsAuthConfig();
            var client   = ArmHelper.GetWebSiteManagementClient(settings);

            var site  = client.Sites.GetSite(settings.ResourceGroupName, settings.WebAppName);
            var model = new HostnameModel();

            model.HostNames         = site.HostNames;
            model.HostNameSslStates = site.HostNameSslStates;
            model.Certificates      = client.Certificates.GetCertificates(settings.ServicePlanResourceGroupName).Value;
            model.InstalledCertificateThumbprint = id;
            if (model.HostNames.Count == 1)
            {
                model.ErrorMessage = "No custom host names registered. At least one custom domain name must be registed for the web site to request a letsencrypt certificate.";
            }

            return(View(model));
        }