Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet run command not listening on https

I am running a simple ASP.Net program on Windows and when I try to run the dotnet run command, I can see it's listening only on http but not on https. I have also executed dotnet dev-certs https --trust command to trust the development certificate, but still it's not listening on https. Could you please let me know if I am missing any other settings ?

PS C:\Users\test\Documents\TodoApi> dotnet  run 
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5027
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\test\Documents\TodoApi

launchsettings.json

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:40409",
      "sslPort": 44321
    }
  },
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5027",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7130",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
like image 723
sunny kumar Avatar asked Nov 15 '25 03:11

sunny kumar


1 Answers

This issue happened because the command dotnet run automatically takes the first profile, i.e. http, in your appsettings.json file.

You have a few options to launch the https profile:

Option 1

You can use the .NET CLI command:

dotnet run --launch-profile https

Notes: This is also the answer as mentioned by avardag.

Option 2

You can move the https profile upwards like this:

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:40409",
      "sslPort": 44321
    }
  },
  "profiles": {
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7130",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5027",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

In your question, you can see the profiles' sequence is http, https, and IIS Express, but I made some arrangements to put https before http.

Now, when you run dotnet run command, you will see the https like this:

PS C:\Users\test\Documents\TodoApi> dotnet  run 
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7130
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5027
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\test\Documents\TodoApi
like image 187
Chan Guan Yu Avatar answered Nov 17 '25 18:11

Chan Guan Yu