admin管理员组

文章数量:1390895

Question

Why does dotnet run in my ASP.NET Core Web API use http only, and not using https, as well?

Details

I am working on Exercise - Create a minimal API from the ASP.NET team. According to item 3 of Scaffold a Project section of this exercise, the output of dotnet run command should also include https path, say, https://localhost:7200.

But, on my Windows 10 machine, the output includes only http path (as shown below) despite the fact that I have first run the dotnet dev-certs https --trust to trust the self-singing certificate.

Command to trust the certificate

PS C:\Users\MyUserName> dotnet dev-certs https --trust
Trusting the HTTPS development certificate was requested. A confirmation prompt will be displayed if the certificate was not previously trusted. Click yes on the prompt to trust the certificate.
Successfully trusted the existing HTTPS certificate.

Output of dotnet run

PS C:\Users\MyUserName\PizzaStore> dotnet run
Using launch settings from C:\Users\MyUserName\PizzaStore\Properties\launchSettings.json...
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5192
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\MyUserName\PizzaStore

Question

Why does dotnet run in my ASP.NET Core Web API use http only, and not using https, as well?

Details

I am working on Exercise - Create a minimal API from the ASP.NET team. According to item 3 of Scaffold a Project section of this exercise, the output of dotnet run command should also include https path, say, https://localhost:7200.

But, on my Windows 10 machine, the output includes only http path (as shown below) despite the fact that I have first run the dotnet dev-certs https --trust to trust the self-singing certificate.

Command to trust the certificate

PS C:\Users\MyUserName> dotnet dev-certs https --trust
Trusting the HTTPS development certificate was requested. A confirmation prompt will be displayed if the certificate was not previously trusted. Click yes on the prompt to trust the certificate.
Successfully trusted the existing HTTPS certificate.

Output of dotnet run

PS C:\Users\MyUserName\PizzaStore> dotnet run
Using launch settings from C:\Users\MyUserName\PizzaStore\Properties\launchSettings.json...
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5192
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\MyUserName\PizzaStore
Share Improve this question edited Mar 16 at 17:38 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 16 at 17:28 namnam 24k45 gold badges189 silver badges402 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 2

We can find launchSettings.json file under the Properties folder.

Under profiles, we can see that the first default is http, the second is https, and the third is IIS Express. When we execute dotnet run, the default startup item will use http.

So there are 2 ways to fix the issue.

1. Use below command to start the application manually.
dotnet run --launch-profile https

2. Change the https order in profiles
{
  "$schema": "http://json.schemastore./launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:41731",
      "sslPort": 44378
    }
  },
  "profiles": {
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7188;http://localhost:5108",
      "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5108",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },

    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
       }
    }
  }
}

Then run the command dotnet run, it will use https by default.

本文标签: ASPNET Core Web API routing is not using httpsStack Overflow