Asp.net core IdentityServer4,WindowsCryptographicException:系统找不到指定的文件

Asp.net core IdentityServer4,WindowsCryptographicException:系统找不到指定的文件,asp.net-core,identityserver4,openid-connect,Asp.net Core,Identityserver4,Openid Connect,我创建了一个带有多个客户端应用程序的IdentityServer4项目。我使用自签名证书文件my_certificate.pfx生成登录令牌。它在本地主机上运行良好 但是,将其用于共享web托管服务器时,它不起作用 托管IdentityServer4的应用程序工作正常,表明服务器应用程序可以访问证书文件。但是,尝试从客户端应用程序登录时会生成以下错误: WindowsCryptographicException:系统找不到指定的文件。 System.Security.Cryptography.

我创建了一个带有多个客户端应用程序的IdentityServer4项目。我使用自签名证书文件my_certificate.pfx生成登录令牌。它在本地主机上运行良好

但是,将其用于共享web托管服务器时,它不起作用

托管IdentityServer4的应用程序工作正常,表明服务器应用程序可以访问证书文件。但是,尝试从客户端应用程序登录时会生成以下错误:


WindowsCryptographicException:系统找不到指定的文件。
System.Security.Cryptography.CngKey.Open(字符串键名、CngProvider提供程序、CNGKEYOPTIONS)
System.Security.Cryptography.CngKey.Open(字符串键名,CngProvider提供程序)
内部.Cryptography.Pal.CertificatePal.GetPrivateKey(Func createCsp,Func createCng)
Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey()
System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKey()
Microsoft.IdentityModel.Tokens.X509SecurityKey.get_PrivateKeyStatus()
Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider.FoundPrivateKey(SecurityKey)
Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(SecurityKey、字符串算法、布尔willCreateSignatures)
Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(安全密钥、字符串算法、布尔willCreateSignatures、CryptoProviderFactory CryptoProviderFactory)
Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider(安全密钥、字符串算法、布尔willCreateSignatures)
Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateForSigning(SecurityKey,字符串算法)
Microsoft.IdentityModel.JsonWebTokens.JwtTokenUtilities.CreateEncodedSignature(字符串输入,签名凭据签名凭据)
System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken令牌)
IdentityServer4.Services.DefaultTokenCreationService.CreateJwtAsync(JWTSecurityTokenJWT)
IdentityServer4.Services.DefaultTokenCreationService.CreateTokeSync(令牌令牌)
IdentityServer4.Services.DefaultTokenService.CreateSecurityTokenAsync(令牌)
IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateImplicitFlowResponseAsync(ValidateAuthorizerRequest,字符串授权代码)
IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateHybridFlowResponseAsync(ValidatedAuthorizerRequest请求)
IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizerRequest请求)
IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection参数、ClaimsPrincipal用户、同意响应同意)
IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext上下文)
IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext上下文、IEndpointRouter路由器、IUserSession会话、IEventService事件)
IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext上下文、IEndpointRouter路由器、IUserSession会话、IEventService事件)
IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext上下文,IAAuthenticationSchemeProvider方案)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext上下文)
IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext上下文)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext上下文)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext上下文)
NWebsec.AspNetCore.Middleware.Middleware.base.Invoke(HttpContext上下文)
NWebsec.AspNetCore.Middleware.Middleware.base.Invoke(HttpContext上下文)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文)

如何使客户端应用程序工作


谢谢

我在AWS ElasticBeanstalk基础设施上设置IdentityServer并使用本地文件而不是证书存储时遇到了这个问题,不过我的解决方案是相同的。我发现EC2实例上的应用程序池没有将Load User Profile设置为true。设置后,权限模型将更改,并允许进程加载到证书中。您可以通过应用程序池详细信息上的IIS管理UI启用,或使用下面的脚本版本

Import-Module WebAdministration
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name "processModel.loadUserProfile" -Value "True"

你找到解决办法了吗?有完全相同的问题这个答案为我解决了这个问题:
Import-Module WebAdministration
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" -Name "processModel.loadUserProfile" -Value "True"