![](/img/trans.png)
[英]how do launchSettings.json and appSettings.json work?
[英]launchSettings.json launchUrl doesn't work "api/values"
我正在尝试更改http://localhost:5001/api/values路由,但程序卡住了这个 url。
我读了这个解决方案
如何更改 ASP.NET Core API 中的默认控制器和操作?
如何在 Asp.Net Core 2.x 中将 root 重定向到 swagger?
https://medium.com/quick-code/routing-in-asp-net-core-c433bff3f1a4
每个人都写同样的东西,但不适合我。
我的launchSetting.json
文件是
{ "$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54650",
"sslPort": 44382
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ShoppingBasketAPI": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
我试图改变app.UseMvc();
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2
这也不起作用api/values
来自哪里? 我想不通。
我的控制器属性路由是[Route("api/[controller]/[action]")]
当您创建新的 ASP.Net Core Web API 项目时,您将看到在项目属性中有设置为api/values
路径的Launch browser
设置。 因此,您可以将其更改为您想要的任何网址,或者您可以在 launchSetting.json 文件中进行更改
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54356",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication4": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
所以你会在配置文件部分看到有 2 个配置。 一种用于 IIS express(使用 Visual Studio 运行代码时)和 WebApplication4(使用 dotnet run 运行项目时),因此您可以更改为
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54356",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication4": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
因此,当您使用 VS 运行项目或dotnet run
命令时,将始终首先提供 swagger url。
我正在使用 VSCode 并且在我身上发生了同样的事情,但是在 Windows 上。 我只是在这里加强一点答案。
我已经尝试过 VS2019 并且它在那个 IDE 中工作,所以它应该与 VSCode 有关。 我已经搜索了其他答案,我找到了这个。
解决我的问题的是转到 .vscode/launch.json 文件并附加:
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}/swagger"
}
正如 Anton Dremin 所描述的,只需将上述内容添加到配置部分即可。
问题是因为 Visual Studio for Mac。 我能够获得正确的 url 来Run With>Custom Configuration > Run Action --> Debug .Net Core Debugger
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.