LucaA LucaA - 1 year ago 525
ASP.NET (C#) Question

Use https with Microsoft.AspNetCore.Server.WebListener

I need to configure a core web application with WebListener as server and https procotols. I wasn't able to find any documentation or faqs about that.

My Progam.cs is:

var host = new WebHostBuilder()
.UseWebListener(options => {

.UseUrls("http://localhost:5001", "https://localhost:5002")


What can I do for configure WebListener in https?

Thanks all in advance!

Answer Source

One way is to bind your SSL certificate to the specific port that your WebListener is listening on, using the netsh command. See How to: Configure a Port with an SSL Certificate for more information on how to do this. After the certificate is bound to the port, you can specify an https url for your WebListener. You can write code to do the netsh part for you (before you start your WebListener), but that probably falls outside the scope of this question.

Enabling https is a lot simpler in Kestrel - any specific reason why you want to use a WebListener? When using Kestrel, you can do the following (there are also several other overrides that you can use, e.g. use cert from store):

new WebHostBuilder().UseKestrel(options => options.UseHttps(@"C:\MyCert.pfx"));

Remember to include the Microsoft.AspNetCore.Server.Kestrel.Https package in your project.json file.

I also found this question on StackOverflow that may help to point you in the right direction.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download