我在Azure上托管了一个Identity Server Web应用程序.它的根目录中有一个.pfx文件用于签名.问题是,当新发布它完全正常但在一段时间后它开始抛出CryptographicException:Keyset不存在.
基于CryptographicException KeySet does not exists我会认为这是一个文件访问问题,但是为什么突然出现的azure会搞乱文件访问.
解决方法:
我建议您不要先从磁盘检索签名证书.而是将证书上传到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];