Identityserver4 如何正确安装identityserver 4证书?

Identityserver4 如何正确安装identityserver 4证书?,identityserver4,Identityserver4,我有这样一个问题: 我正试图通过这种方式为我的identityserver 4安装证书 var path = Path.Combine(Environment.ContentRootPath, "IdentityServer4_certificate.pfx"); var certificate = new X509Certificate2(path, "Password"); 通过本项目认证 在本地计算机上启动时,它可以工作,但在发布到Window

我有这样一个问题: 我正试图通过这种方式为我的identityserver 4安装证书

var path = Path.Combine(Environment.ContentRootPath, "IdentityServer4_certificate.pfx");

var certificate = new X509Certificate2(path, "Password");
通过本项目认证

在本地计算机上启动时,它可以工作,但在发布到Windows时,服务器会给出一个错误:

Host terminated unexpectedly.

Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Внутренняя ошибка.
   at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(Byte[] rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)
   at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
   at IdentityServer.Startup.ConfigureServices(IServiceCollection services) in C:\Users\b.ismail\Source\Repos\identityserver4Original\IdentityServer\Startup.cs:line 111
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at IdentityServer.Program.Main(String[] args) in C:\Users\b.ismail\Source\Repos\identityserver4Original\IdentityServer\Program.cs:line 44
主机意外终止。
内部.加密.加密密码器+窗口加密例外:Сааааааа。
位于Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(字节[]rawData,安全密码句柄密码,PfxCertStoreFlags PfxCertStoreFlags)
位于Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(字节[]rawData,字符串文件名,安全密码句柄密码,X509keystrageFlags keystrageFlags)
位于System.Security.Cryptography.X509Certificates.X509Certificate..ctor(字符串文件名、字符串密码、x509keystrageflags keystrageflags)
位于System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(字符串文件名、字符串密码、X509KeyStrageFlags KeyStrageFlags)
在C:\Users\b.ismail\Source\Repos\IdentityServer 4Original\IdentityServer\Startup.ConfigureServices(IServiceCollection services)中的C:\Users\b.ismail\Repos\IdentityServer 4Original\IdentityServer\Startup.cs:第111行
在System.RuntimeMethodHandle.InvokeMethod(对象目标、对象[]参数、签名符号、布尔构造函数、布尔WrapeExceptions)
在System.Reflection.RuntimeMethodInfo.Invoke(对象obj、BindingFlags invokeAttr、绑定器绑定器、对象[]参数、CultureInfo区域性)
位于Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(对象实例,IServiceCollection服务)
在Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.c_uuDisplayClass9_0.g_uStartup | 0(IServiceCollection serviceCollection)
位于Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(对象实例,IServiceCollection服务)
在Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.c__DisplayClass8_0.b__0(iSeries收集服务)上
在Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(键入startupType、HostBuilderContext上下文、IServiceCollection服务)
在Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.c__DisplayClass12_0.b__0(HostBuilderContext上下文,IServiceCollection服务)
在Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()上
在Microsoft.Extensions.Hosting.HostBuilder.Build()上
在C:\Users\b.ismail\Source\Repos\identityserver4Original\IdentityServer\Program.cs中的IdentityServer.Program.Main(字符串[]参数)处:第44行
第111行是
var certificate=new X509Certificate2(路径,“密码”)

此外,公钥通过MMС安装在Windows服务器上


如何正确安装证书?

在读取证书之前,请尝试记录路径。可能存在以下情况之一:找不到文件,访问被拒绝。只是把证书放在旁边比较简单。在这种情况下,它只是一个文件,不需要安装它。