Visual Studio Code launchurl not working on Web API

Viewed 374

I am trying to follow this tutorial: https://code.visualstudio.com/docs/containers/quickstart-aspnet-core

In the section "Debug in container" I am having issues with debugging this application. When I run the debugger, the chrome browser opens up to http://localhost:7009 and displays the following error:

This localhost page can’t be foundNo webpage was found for the web address: http://localhost:7009/
HTTP ERROR 404

The problem is that the launchurl that is specified within the launchSetting.json file does not seem to be working. Here is the launchSettings.json file:

"profiles": {
    "TodoApi": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "WeatherForecast",
      "applicationUrl": "https://localhost:7009;http://localhost:5189",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "WeatherForecast",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }

I have specified the launchUrl to "WeatherForecast" so that when the browser launches it should go to https://localhost:7009/WeatherForecast but that's not happening.

I tried setting applicationUrl to "https://localhost:7009/WeatherForecast" but that generates an error during build.

I am running Visual Studio Code for Mac if that makes any difference.

Thanks for any help!

1 Answers

If you are using the OmniSharp plugin you can fix this the following way.

In ./.vscode/launch.json modify serverReadyAction and add uriFormat to be the URL that you want.

        "serverReadyAction": {
            "action": "openExternally",
            "pattern": "\\bNow listening on:\\s+http://\\S+:([0-9]+)",
            "uriFormat": "http://localhost:%s/WeatherForecast"
        },
Related