gpt4 book ai didi

c# - 从证书存储 C# MVC 获取 X509Certificate 列表

转载 作者:可可西里 更新时间:2023-11-01 11:27:20 24 4
gpt4 key购买 nike

我正在尝试从证书库中获取证书列表。这是我在这篇文章 Get list of certificates from the certificate store in C# 中使用的代码:

X509Store store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 mCert in store.Certificates)
{
// TODO
}

当我从 Test Explorer 运行这段代码时,它找到了所有可用的证书,但是当我在我的 MVC 应用程序上运行它时,却没有返回任何证书。我以管理员身份运行 VS 2013。

你能告诉我我做错了什么吗?

编辑:

当我在 IIS Express 上运行代码时,我得到了证书列表,但是当我在本地 IIS 上运行它时,我没有得到任何结果。

问候,

最佳答案

大多数时候,您想检查机器存储证书,而不是当前用户的证书。为此:

X509Store store = new X509Store(StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
foreach (X509Certificate2 certificate in store.Certificates)
{
// TODO
}

无论 IIS 用户如何,这都会为您提供一致的列表。

关于c# - 从证书存储 C# MVC 获取 X509Certificate 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31924604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com