将 IdentityServer 4 部署到 Azure 应用服务

deploying identityserver 4 to azure app service

将包含 identityserver 4 的 blazor 应用程序部署到 azure 应用程序服务时,出现以下异常:

Exception Info: System.InvalidOperationException: There was an error loading the certificate. Either the password is incorrect or the process does not have permisions to store the key in the Keyset 'DefaultKeySet'

证书来自 azure keyvault,本地没有问题。 在我用来调用证书并将其加载到身份服务器签名凭证的代码下方:

var pfx = Configuration["certname"];
var bytes = Convert.FromBase64String(pfx);
var certificate2Collection = new X509Certificate2Collection();
certificate2Collection.Import(bytes, null, X509KeyStorageFlags.UserKeySet);

services.AddIdentityServer()
.AddSigningCredential(certificate2Collection[0]);

关于如何解决这个问题有什么想法吗?

大量搜索给了我答案。

我需要做两件事。

首先我需要在 Azure 上的服务应用程序中添加证书:

然后在服务应用程序的配置中,我需要添加一个应用程序设置: WEBSITE_LOAD_CERTIFICATES 以证书指纹作为值:

之后发现证书没有问题。