其他分享
首页 > 其他分享> > .net5证书

.net5证书

作者:互联网

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder
                    .UseUrls($"http://{ip}:{port}", $"https://{ip}:7006")
                    .UseStartup<Startup>()
                    ;
                    webBuilder.ConfigureKestrel(kerstrel =>
                    {
                        kerstrel.ConfigureHttpsDefaults(https =>
                        {
                            //var serverPath = AppDomain.CurrentDomain.BaseDirectory + "cert\\server.pfx";
                            var serverPath = @"D:\work\code\test\cer\socialnetwork.pfx";
                            var serverCertificate = new X509Certificate2(serverPath, "Test");
                            https.ServerCertificate = serverCertificate;
                            https.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
                            https.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls | SslProtocols.None | SslProtocols.Tls11;
                            https.ClientCertificateValidation = (cer, chain, error) =>
                            {
                                return chain.Build(cer);
                            };

                        });
                    });

                })
                .UseWindowsService();

标签:SslProtocols,证书,cer,https,var,webBuilder,net5,serverPath
来源: https://www.cnblogs.com/ives/p/16059082.html