1

我的Azure Web角色(云服务,而不是WebApp)需要支持客户端证书。SslRequireCert和Azure Web角色

我发现我可以通过包含的WebRole.cs代码片段来更改网站的配置。部署时,IIS中的客户端证书设置发生更改(当我远程访问服务器时),但它不起作用,并且出现授权错误。但是,如果我手动在IIS管理器中单击/需要SSL证书和“应用更改”,一切似乎都起作用。 Webrole正在ELEVATED模式下运行。我错过了什么?

public override bool OnStart() 
{ 
    try 
    { 
     using (var server = new ServerManager()) 
     { 
      const string siteNameFromServiceModel = "Web"; // TODO: update this site name for your site. 
      var siteName = string.Format("{0}_{1}", RoleEnvironment.CurrentRoleInstance.Id, siteNameFromServiceModel); 

      var config = server.GetApplicationHostConfiguration(); 
      var accessSection = config.GetSection("system.webServer/security/access", siteName); 
      accessSection["sslFlags"] = @"Ssl,SslRequireCert"; 

      server.CommitChanges(); 
     } 
    } 
    catch (Exception ex) 
    { 
     // handle error here 

    } 
    return base.OnStart(); 
} 

回答

1

看来,我需要有plased SslNegotiateCert设定为好,像这样:

     accessSection["sslFlags"] = @"Ssl, SslNegotiateCert, SslRequireCert"; 
+0

这是非常有益的 –

0

您是否在服务定义中设置了证书?

<ServiceDefinition …> 
    <WebRole name="<web-role-name>" vmsize="<web-role-size>" enableNativeCodeExecution="[true|false]"> 
    <Certificates> 
     <Certificate name="<certificate-name>" storeLocation="<certificate-store>" storeName="<store-name>" /> 
    </Certificates>  
    ... 

https://msdn.microsoft.com/en-us/library/azure/gg557553.aspx

+0

没错。这是公认的和网站上的SSL作品 – Igorek