This article is contributed. See the original author and article here.

Pre-requirement:  




Now, have two domain names: www.haileyding.site, and www.dinghan.site 


Also, two certificates uploaded to my Cloud Service:  


hailey_ding_0-1602405224618.png


 


 


 


Steps: 


The main changes happen on the .csdef file, .cscofg file, and also the OnStart method in the WebRole.cs. 



  1. Add the two domain name in the definition file,  named with ‘ServiceDefinition.csdef 


Refer to this document about how to modify the service definition and configuration files. 


hailey_ding_1-1602405224638.png


 


 


 



  1. Add my two certificates into the configuration file, named with ‘ServiceConfiguration.Cloud.cscfg 


hailey_ding_2-1602405224629.png


 


 


 



  1. Since we cannot assign the same local port to multiple endpoints, so we need to override the OnStart method of the RoleEntryPoint class to overcome this issue.  


Please be noticed that the executionContext must be set to elevated, otherwise it is not possible for the OnStart method to edit the bindings. 


 


Navigate to the WebRole1 -> WebRole.cs, in this file, we can configure our OnStart method as below: 


 


hailey_ding_3-1602405224631.png


 


 


 


namespace WebRole1 


{ 


    public class WebRole : RoleEntryPoint 


    { 


        public override bool OnStart() 


        { 


            using (var serverManager = new ServerManager()) 


            { 


                foreach (var site in serverManager.Sites.ToArray()) 


                { 


                    foreach (var binding in site.Bindings.ToList()) 


                    { 


                        if (binding.Protocol == “https”) 


                        { 


                            var newbinding = site.Bindings.CreateElement(“binding”); 


                            newbinding.SetAttributeValue(“sslFlags“, 1); 


                            newbinding.BindingInformation = binding.BindingInformation.Replace(“:444:”, “:443:”); 


                            newbinding.CertificateHash = binding.CertificateHash; 


                            newbinding.CertificateStoreName = binding.CertificateStoreName; 


                            newbinding.Protocol = “https”; 


                            site.Bindings.Remove(binding); 


                            site.Bindings.Add(newbinding); 


                        } 


                    } 


                } 


 


                serverManager.CommitChanges(); 


            } 


            RoleEnvironment.Changing += RoleEnvironmentChanging; 


            return base.OnStart(); 


        } 


        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e) 


        { 


            e.Cancel = true; 


        } 


    } 


} 


 



  1. Deploy the changes to my Cloud Service, then verify my custom domain name with HTTPS 


hailey_ding_4-1602405224634.png


 


 


 


hailey_ding_5-1602405224624.png


 


 


 


 


Reference: https://raflrx.wordpress.com/2017/08/08/enable-sni-on-a-windows-azure-cloud-service/ 


 

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.

%d bloggers like this: