Wednesday, April 17, 2019

(Solved) .Net core web api project with vscode keep giving HTTPS endpoints can only be configured using KestrelServerOptions.Listen()

Leave a Comment
Problem:

While working for Angular project with .net core web api using Json web token for angular security, we might get exception in program.cs file of Web API of project developed in .net core

public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}


While debugging project in vscode to run web api we find following exception:

asp.net core web api System.InvalidOperationException: HTTPS endpoints can only be configured using KestrelServerOptions.Listen(). at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.<BindAddressAsync>d__7.MoveNext()


Solution:

We need to disable / Commented out / remove https: from applicationUrl in launchSettings.json

"ProjectApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
//"applicationUrl": "https://localhost:5001;http://localhost:5000",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

The reason from .net core 2.1 and onward this launchSettings.json is include as template as we create .net core project. However, this wasn't happening prior to .net core 2.0 and previous versions.

So updating applicationUrl in launchSettings.json under Properties folder would do the trick and web api should start working as expected
If You Enjoyed This, Take 5 Seconds To Share It

0 comments: