调试asp.net核心API/REST应用程序:更改defauilt路径
问题描述:
我有一个ASP.NET Core web API;这是一个简单的休息界面。调试asp.net核心API/REST应用程序:更改defauilt路径
在项目属性,我有这样的路径:
,但是当我在调试器启动,它总是转到:
http://localhost:58187/api/values
调试器加载时浏览器,在这里是网址:
data:text/html;charset=utf-8,<head><meta http-equiv="refresh" content="0; url=http://localhost:58187/api/values"/></head><body><style>body{margin:25px;font:16px calibri,'segoe ui'}</style><h3>Chrome script debugging in Visual Studio is enabled</h3><ul><li>Set breakpoints in JavaScript/TypeScript in Visual Studio</li><li>Automatically break on script errors</li><li>Opening developer tools in Chrome stops the script debugging session</li></ul><a href='https://aka.ms/chromedebugging' target='_blank'>Learn more about Chrome debugging in Visual Studio</a><h4><i>Your application is starting...</i></h4></body><!---->
我可以看到api/values
初始Url中的字符串。
如何更改api/values
字符串?
答
在Visual Studio启动设置中配置在运行或调试应用程序时在浏览器中打开的默认启动路径。这些可以在Properties/launchSettings.json
中配置。在该文件中,会出现这样的部分:
"profiles": {
"profileName": {
"commandName": "…",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
}
可能有多个配置文件,通常至少有一个“IIS快车”和一个具有相同的名称为您的应用程序。这些配置文件与您从Visual Studio的调试按钮(带有绿色播放图标的按钮)下拉菜单相匹配。
正如您从配置中看到的,有一个launchUrl
配置,它具有api/values
值。这是浏览器默认打开的路径。您可以将其更改为任何您想让浏览器走到需要的位置。
您还可以创建新的启动配置文件,以便为每个主控制器或其他配置文件配置不同的配置文件。当然,您也可以禁用launchBrowser
设置,以避免浏览器每次打开,允许您自己打开网站(或只保留一个标签页)。