[英]Read embedded file from resource in asp.net core
將我的網站發布到iis后,出現錯誤消息:
Internal.Cryptography.CryptoThrowHelper + WindowsCryptographicException:系統找不到指定的文件
我從嵌入式文件讀取X509Certificate2的代碼是:
X509Certificate2 certificate = null;
using (var certStream = typeof(T).Assembly.GetManifestResourceStream(resourceName))
{
using (var memory = new MemoryStream((int)certStream.Length))
{
certStream.CopyTo(memory);
certificate = new X509Certificate2(memory.ToArray(), password);
}
}
此錯誤僅在Windows服務器IIS中發生,但如果直接在IIS Express中運行Kestrel,則沒有問題。
它會將文件讀為非托管內存。
我遇到了同樣的問題,添加X509KeyStorageFlags.MachineKeySet可以解決問題。
certificate = new X509Certificate2(memory.ToArray(), password, X509KeyStorageFlags.MachineKeySet);
在這里找到解決方案:
https://github.com/dotnet/corefx/issues/27358#issuecomment-385433985 ,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.