【发布时间】:2021-07-02 22:48:46
【问题描述】:
我正在尝试从远程计算机的证书存储中获取未过期证书的列表。对于某些机器,这可以正常工作,但对于其他机器,我收到以下错误:
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The network path was not found.
at Internal.Cryptography.Pal.StorePal.FromSystemStore(String storeName, StoreLocation storeLocation, OpenFlags openFlags)
at System.Security.Cryptography.X509Certificates.X509Store.Open(OpenFlags flags)
at GetCertificates(String server)
这是这段代码的来源:
var store = new X509Store($@"\\{server}\My", StoreLocation.LocalMachine);
var certList = new List<X509Certificate2>();
try
{
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
certList = store.Certificates.Cast<X509Certificate2>()
.Where(x => x.NotBefore < DateTime.Now &&
DateTime.Now < x.NotAfter).ToList();
}
catch (Exception e)
{
throw;
}
finally
{
store.Close();
}
任何想法为什么这可能发生在某些机器和/或可能的解决方法/解决方案上?
谢谢
【问题讨论】:
-
根据constructor doc,
new X509Store(this is a name, this is a location type)。但您的第一个实际参数是共享文件夹路径,而不是名称。 -
@LeiY,我基于此解决方案的代码,建议可以使用远程路径/UNC:stackoverflow.com/a/30945625/2048464
标签: c# .net-core x509certificate2