Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kestrel UseHttps() method signature changed in .net core 2

Tags:

asp.net-core

I have written an ASP.NET application that is based on .NET core 1.1. This application works as expected. Today, I just upgraded my server to dotnet-sdk-2.0.0-preview2-006497 and made necessary changes in the .csproj file.

In my application's main method, I have the following code:

 var host = new WebHostBuilder()
    .UseKestrel(options => {
       options.UseHttps("MyCert.pfx");
    })
    ...

This code used to work fine under .net core 1.0 but gives an error under .net core 2.0.

KestrelServerOptions does not contain a definition for UseHttps and
the best extension method overload
ListenOptionsHttpsExtensions.UseHttps(ListenOptions, string) requires
a receiver of type ListenOptions

I am wondering how I can fix this. Can I just pass null as a parameter? Regards.

like image 593
Peter Avatar asked Jul 20 '17 05:07

Peter


People also ask

How do I change the port on my Kestrel?

You can set the Kestrel ports inside the appsettings. json file. A simple block of JSON does it. You might notice that there is an appsettings.Development.

What is use of Kestrel in .NET Core?

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. Opaque upgrade used to enable WebSockets.

Which ASP.NET Core no longer depends on the system?

Fast: ASP.NET Core no longer depends on System. Web. dll for browser-server communication. ASP.NET Core allows us to include packages that we need for our application.

How do I host a .NET Core application in Kestrel?

In the case of the Kestrel web server, the process name that is used to host and run the ASP.NET Core application is the project name. As of now, we are using visual studio to run the ASP.NET Core application. By default, the visual studio uses IIS Express to host and run the ASP.NET Core application.


1 Answers

This is a breaking change, see this announcement, the important bit being:

There is no overload on .Listen() that allows you to configure an SSL cert without using an options lambda.

In other words you can only add HTTPS within or with some listen options. The simplest alternative would be:

var host = new WebHostBuilder()
    .UseKestrel(options =>
        options.Listen(IPAddress.Any, 443, listenOptions =>
                listenOptions.UseHttps("MyCert.pfx")))
        ...

So you're saying listen on any assigned IP using port 443.

like image 74
Matt Avatar answered Jan 04 '23 11:01

Matt