Visual Studio代码启动程序无法在Web API上运行



我正在努力学习本教程:https://code.visualstudio.com/docs/containers/quickstart-aspnet-core

在";在容器中调试";我在调试此应用程序时遇到问题。当我运行调试器时,chrome浏览器会打开http://localhost:7009并显示以下错误:

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

问题是在launchSetting.json文件中指定的launchchurl似乎不起作用。这是launchSettings.json文件:

"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"
}
}

我已将launchUrl指定为";WeatherForecast";这样,当浏览器启动时,它应该转到https://localhost:7009/WeatherForecast但这并没有发生。

我尝试将applicationUrl设置为";https://localhost:7009/WeatherForecast"但这会在构建过程中产生错误。

如果有什么不同的话,我正在运行Visual Studio Code for Mac。

谢谢你的帮助!

如果您正在使用OmniSharp插件,您可以通过以下方式修复此问题。

英寸/英寸。vscode/launch.json修改serverReadyAction并添加uriFormat作为您想要的URL。

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

在我的情况下,它只显示URL(https://localhost:7009)在.net 6.0中。所以https://localhost:7009/swagger/index.html.它工作

最新更新