I am currently using ASP.NET Core 2.x and I used to be able to get Kestrel to to use HTTPS / SSL by simply putting it in the UseUrls()
method like so:
var host = new WebHostBuilder() .UseUrls("http://localhost", "https://111.111.111.111") .UseKestrel() .Build();
But now I get the exception:
System.InvalidOperationException: HTTPS endpoints can only be configured using KestrelServerOptions.Listen().
How do I configure Kestrel to use SSL in ASP.NET Core 2.x?
Kestrel server is the default, cross-platform HTTP server. HTTP. sys server is a Windows-only HTTP server based on the HTTP. sys kernel driver and HTTP Server API.
Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included by default in ASP.NET Core project templates. Kestrel supports the following scenarios: HTTPS.
Yes, Kestrel is production ready and is supported on all platforms and versions that . NET Core supports, but if your application is available on public networks Microsoft recommend that you use it with a reverse proxy: Even if a reverse proxy server isn't required, using a reverse proxy server might be a good choice.
If you want to associate your server to use all the IP addresses assigned to the server/web host then you can do this:
WebHost.CreateDefaultBuilder(args) .UseUrls("http://localhost:5000", "http://*:80") .UseStartup<Startup>() .Build();
Note: The string format used in the UseUrls()
method is: http://{ip address}:{port number}
.
- If you use an *
(asterisks) for the IP address, that means all available IP address on the host.
- The port number is not a requirement. If you leave it blank it will default to port 80.
There is a great amount of additional detail about the UseUrls()
method over at the official Microsoft Docs here.
However, SSL will not work with the
UseUrls()
method --- so, that means if you try to add a URL starting withhttps://
the program will throw the exceptionSystem.InvalidOperationException: HTTPS endpoints can only be configured using KestrelServerOptions.Listen().
HTTPS endpoints can only be configured using KestrelServerOptions
.
Here is an example of using TCP sockets using the Listen
method:
WebHost.CreateDefaultBuilder(args) .UseKestrel(options => { options.Listen(IPAddress.Loopback, 5000); // http:localhost:5000 options.Listen(IPAddress.Any, 80); // http:*:80 options.Listen(IPAddress.Loopback, 443, listenOptions => { listenOptions.UseHttps("certificate.pfx", "password"); }); }) .UseStartup<Startup>() .Build();
Note: That if you use both the Listen
method and UseUrls
, the Listen
endpoints override the UseUrls
endpoints.
You can find more info about setting up endpoints here at the official Microsoft Docs.
If you use IIS, the URL bindings for IIS override any bindings that you set by calling either
Listen
orUseUrls
. For more information, see Introduction to ASP.NET Core Module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With