我们可以使用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>
解决方法
是的,据我所知,没有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");