I need to debug external authentication and it requires HTTPS. At the same time for most internal requests http is enough. There was no problem to listen on 80 and 443 ports when hosting my web app on IIS, but with ASP.NET Core hosted by Kesterl as I see it, the port is strictly bind to specific configuration in launchSettings.json such as:

"localCalls": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:40000"
    },
"externalIdentity": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:50000"
    }

I'm curiuse, is it possible to have listeners on both ports at a time without necessarity to relaunch in the other configuration to change the protocol.

2 Answers

1
Community On Best Solutions

According to the documentation you can define the endpoints within the same configuration:

"localCalls": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "ASPNETCORE_URLS": "http://localhost:5000;https://localhost:5100"
      }
    }
1
Shahzad Hassan On

Asp.Net Core 2.1 and onwards makes it super easy to use local SSL. When you create the project using Visual Studio, it asks you if you need to enable the SSL or not. If you selected that option before creating the project, you should see your launchSettings.json file something like below:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:61110",
      "sslPort": 44377
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "YourProjectName": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

The iisSettings section is for IISExpress with an sslPort defined i.e. 44377 in this case. So when your project runs under IISExpress, it uses that settings

The YourProjectName section is for Kestrel. You can see that applicationUrl is using both http and https endpoints. So when you do dotnet run you should see

Hosting environment: Development
Content root path: C:\users\...\YourProjectName
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000

In addition, under Configure method, you should see a line below, so it will automatically redirect HTTP to HTTPS

app.UseHttpsRedirection();

If your launchSettings.json file doesn't look like the above. Try changing it in the project properties and enable the SSL, like in the screenshot below. When you save the settings, the launchSettings.json file will be updated

enter image description here

If the above doesn't work, try changing the launchSettings.json file manually. I hope that helps