Azure Web应用偶尔会抛出CryptographicException:密钥集不存在

Tam*_*ane 5 c# asp.net azure identityserver4

Identity Server在Azure上托管了一个Web应用程序。它.pfx的根目录中有一个文件用于签名。问题是,当新发布时,它可以很好地工作,但是一段时间后,它会开始抛出CryptographicException: Keyset does not exist.

基于CryptographicException的KeySet不存在,我认为这是一个文件访问问题,但是为什么突然之间的天蓝色却弄乱了文件访问。

Lut*_*ndo 0

我建议您不要首先从磁盘检索签名证书。而是将证书上传到 Azure 门户中关联的 Web 应用程序。

并在应用程序启动时检索证书

就像是。

X509Certificate2 Certificate = null;
var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint,"CERTIFICATE_THUMBPRINT_HERE",false);
Certificate = certCollection[0];
Run Code Online (Sandbox Code Playgroud)