Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 6, 2021 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/bf7a28056d2458a80535971d183e93f6 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/bf7a28056d2458a80535971d183e93f6 to your computer and use it in GitHub Desktop.
Code for setting TLS 1.3 protocol for kestrel and enabling connection logging
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions =>
{
// Set TLS 1.3 protocol for encrypted
serverOptions.ConfigureHttpsDefaults(listenOptions =>
{
listenOptions.SslProtocols = SslProtocols.Tls13;
});
serverOptions.Listen(IPAddress.Loopback, 5000);
serverOptions.Listen(IPAddress.Loopback, 5001, listenOptions =>
{
// Uncomment for logging encrypted HTTP traffic
// listenOptions.UseConnectionLogging();
listenOptions.UseHttps("testCert.pfx", "testPassword");
// For logging decrypted HTTP traffic
listenOptions.UseConnectionLogging();
});
});
webBuilder.UseStartup<Startup>();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment