AspNetCore.Docs/aspnetcore/release-notes/sample/Program7.cs

38 lines
1.1 KiB
C#
Raw Normal View History

// <snippet_1>
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Https;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(8080, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
listenOptions.UseHttps(new TlsHandshakeCallbackOptions
{
OnConnection = context =>
{
var options = new SslServerAuthenticationOptions
{
ServerCertificate =
MyResolveCertForHost(context.ClientHelloInfo.ServerName)
};
return new ValueTask<SslServerAuthenticationOptions>(options);
},
});
});
});
// </snippet_1>
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
X509Certificate MyResolveCertForHost(string serverName)
{
throw new NotImplementedException();
}