.net - 本地 azure 服务结构上的证书空错误
问题描述
尝试在我的本地运行 Azure Service Fabric 应用程序,所有服务都在运行,除了一个抛出证书不能为空异常的服务。下面是获取证书的代码片段。
已在本地计算机和当前用户的本地安装证书。
/// <summary>
/// Finds the ASP .NET Core HTTPS development certificate in development environment. Update this method to use the appropriate certificate for production environment.
/// </summary>
/// <returns>Returns the ASP .NET Core HTTPS development certificate</returns>
private static X509Certificate2 GetCertificateFromStore()
{
string aspNetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (string.Equals(aspNetCoreEnvironment, "Development", StringComparison.OrdinalIgnoreCase))
{
const string aspNetHttpsOid = "1.3.6.1.4.1.311.84.1.1";
const string CNName = "CN=localhost";
using (X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates;
var currentCerts = certCollection.Find(X509FindType.FindByExtension, aspNetHttpsOid, true);
currentCerts = currentCerts.Find(X509FindType.FindByIssuerDistinguishedName, CNName, true);
return currentCerts.Count == 0 ? null : currentCerts[0];
}
}
else
{
throw new NotImplementedException("GetCertificateFromStore should be updated to retrieve the certificate for non Development environment");
}
}
解决方案
您应该尝试将证书文件复制到 Service Fabric 服务帐户可以在启动时获取它们的位置,然后直接读取它们,或者将它们写入以**new X509Store(StoreName.My, StoreLocation.CurrentUser)**
供后续使用。
检查此文档以获取更多参考:
请确保您没有遵循上述场景之一。
您可以使用以[SetupEntryPoint][1]
用户**AccountType="LocalSystem"**
身份运行的 a 来运行SetupEntryPoint
或者,您可以使用 Azure 密钥保管库来存储证书,然后从那里读取它。您可以在此处找到示例代码:
希望能帮助到你。
推荐阅读
- java - 如何使用 BufferedReader 从命令行输出中获取带有特殊字符的字符串
- asp.net - ASP.NET Textbox is losing focus after Postback
- c# - GetInstanceExtensions<> 方法中的工作流扩展 NULL
- string - Hive:删除字符串列中的空格
- sql - 需要获取日期时间范围之间的用户数
- julia - 有没有办法阻止 Julia 使用 BigFloats 的科学(指数)表示法?
- java - 过滤logstash输入
- python - 检索按值排序的值的索引的最pythonic方法是什么?
- php - 如何从保存在数据库中的文本中使用 php 中的 %variable% 等动态变量?
- javascript - Ajax调用好像缓存在IE11里,怎么每次都强制这个调用?