7

我们可以使用 c# 读取带有 ServiceConfiguration.cscfg 文件的证书部分吗?RoleEnvironment 类中有读取 ConfigurationSettings 的方法,但没有读取证书部分。

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="WindowsAzureProject7" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
  <Role name="MvcWebRole1" >
    <Instances count="1" />
       <Certificates>
      <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="625FBBB3B7A25C4B9D1C49D1CB1E3AE196C1A083" thumbprintAlgorithm="sha1" />
    </Certificates>
  </Role>
</ServiceConfiguration>
4

1 回答 1

6

是的,据我所知,没有用于读取证书详细信息的 API,但是您可以做的是创建一个配置设置并添加您的证书特定详细信息,然后直接从同一个 API 中读取它。这是我过去使用的技巧:

<ServiceConfiguration serviceName="RW" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
 <Role name="RR">
  <Instances count="1" />
   <ConfigurationSettings>
    <Setting name="AppFolder" value="RailsApp" />
    <Setting name="CertificateThumb" value="*************" />
   </ConfigurationSettings>
   <Certificates>
    <Certificate name="Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" thumbprint="*****************************" thumbprintAlgorithm="sha1" />
   </Certificates>
 </Role>
</ServiceConfiguration>

现在,在我的角色特定代码中,我可以调用 RoleEnvironment.GetConfigurationSettingValue 来获取证书拇指,如下所示:

string certThumb = RoleEnvironment.GetConfigurationSettingValue("CertificateThumb");
于 2012-07-02T19:05:04.710 回答