使用以下代码示例来指定数字证书的CN名称和主机名。将示例中的“cn_name”和“hostname”替换为实际的CN名称和主机名。
using System.Security.Authentication;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Https;
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel(options =>
{
options.Listen("localhost", 5000, listenOptions =>
{
listenOptions.UseHttps(new HttpsConnectionAdapterOptions
{
ServerCertificate = CertificateHelper.LoadFromStoreCert("cn_name", "My", StoreLocation.CurrentUser, allowInvalid: true),
ClientCertificateMode = ClientCertificateMode.RequireCertificate,
ClientCertificateValidation = CertificateHelper.ValidateClientCertificate,
SslProtocols = SslProtocols.Tls12,
CheckCertificateRevocation = true,
ClientCertificateCollection = CertificateHelper.LoadFromStoreCerts("My", StoreLocation.CurrentUser)
});
});
})
.UseStartup()
.Build();
host.Run();
}
}