azure - IIS https 托管 - 通过代码获取 mmc 安装的证书
问题描述
我通过本地执行过程成功检查了当前用户中是否存在证书。但是当我在 IIS 上发布相同的代码时,我无法获得证书。请指导更改代码或在 IIS 上发布代码的设置。
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
string certThumbprint = "E661583E8FABEF4C0BEF694CBC41C28FB81CD870";
bool validOnly = false;
using (X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
// Replace below with your certificate's thumbprint
certThumbprint,
validOnly);
// Get the first cert with the thumbprint
X509Certificate2 cert = certCollection.OfType<X509Certificate>().FirstOrDefault();
if (cert is null)
throw new Exception($"Certificate with thumbprint {certThumbprint} was not found");
// Use certificate
Console.WriteLine(cert.FriendlyName);
// Consider to call Dispose() on the certificate after it's being used, available in .NET 4.6 and later
}
解决方案
推荐阅读
- python - Flask:使用 GET 请求下载 .zip 文件
- uwp - 将 ItemsSource 更新到 ItemsControl 时,SelectedItem 选择丢失
- android - 如何按行查询房间数据库android kotlin
- android - 当我使用自定义布局而不是通货膨胀时,DialogFragment 什么也不显示
- gcp-load-balancer - 将多个通配符 TLS 证书与单个 GCE 负载均衡器一起使用
- linux - Rust 非交互式标准输入读取
- javascript - 减少 node_modules 后 node_modules 出错
- python - 记录一个mac地址并检查它是否有效
- python - 从偶数索引位置提取字符
- bash - 从第二个函数参数开始的 Ruby for 循环