VSCode webapi default implementation does not run Swagger interface by default, 404 error occurs

Viewed 35

When installing and running a new webapi template in Visual Studio Code:

dotnet new webapi -n weatherapi

the framework is set up to default to launch the Swagger interface, but subsequently executing dotnet run or launching with F5 will attempt to browse to the applicationUrl property specified in launchSettings.json. This subsequently throws a 404 error since this is not the Swagger definition url.

Also within launchSettings.json, launchBrowser defaults to true, and launchUrl defaults to swagger.

According to the documentation, the first entry in the profiles section of launchSettings.json will be the profile used unless specified otherwise in launch.json (which it is not).

So the question is, why does the default implementation throw a 404 when it looks like it should be set up by default to land on the Swagger interface?

The out-of-the-box launchSettings.json implementation is:

{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
  "windowsAuthentication": false,
  "anonymousAuthentication": true,
  "iisExpress": {
    "applicationUrl": "http://localhost:21895",
    "sslPort": 44320
  }
},
"profiles": {
  "weatherapi": {
    "commandName": "Project",
    "dotnetRunMessages": true,
    "launchBrowser": true,
    "launchUrl": "swagger",
    "applicationUrl": "https://localhost:7205;http://localhost:5111",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    }
  },
  "IIS Express": {
    "commandName": "IISExpress",
    "launchBrowser": true,
    "launchUrl": "swagger",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    }
  }
}

}

0 Answers
Related