How to use HTTPS with Kestrel server for the .Net Core web api

Viewed 187

I have created .net core web api. Now its running as the windows background service and its basically listen to the Http request. But I want to change this application to support HTTPS request. So what I did I have changed Program.cs file.

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }
    public static IHostBuilder CreateHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseKestrel(options =>
            {
                options.Listen(IPAddress.Loopback, 5000);  
                options.Listen(IPAddress.Any, 80);         
                options.Listen(IPAddress.Loopback, 443, listenOptions =>
            {
                listenOptions.UseHttps("certificate.pfx", "password");
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            }).UseWindowsService();
            });
}

But here .ConfigureWebHostDefaults(webBuilder => I am getting following error.

Operator '.' cannot be applied to operand of type 'void' [MHScaleInboundWebAPI]csharp(CS0023)

So I need to fix this error and need to correct above class to support with the https request like this. https://localhost:8080/Customer. I need to change this Program.cs calss. I am using 8080 port number.

0 Answers
Related