38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
|
// <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();
|
||
|
}
|