LucaA
LucaA

Reputation: 713

Use https with Microsoft.AspNetCore.Server.WebListener

I need to configure a Asp.net 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 => {

             })                
            .UseContentRoot(Directory.GetCurrentDirectory())               
            .UseIISIntegration()
            .UseUrls("http://localhost:5001", "https://localhost:5002")                
            .UseStartup<Startup>()                
            .Build();

        host.Run();

What can I do for configure WebListener in https?

Thanks all in advance!

Upvotes: 0

Views: 1261

Answers (1)

JC1001
JC1001

Reputation: 516

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.

Upvotes: 2

Related Questions