我正在Visual Studio中开发ASP.NET Core Web API并使用Postman进行测试。如何使Visual Studio在调试时始终在同一端口上启动我的ASP.NET应用程序?
为此,我通过单击Visual Studio中的“运行”按钮来启动集成的IIS Express Server。我希望服务器总是在同一端口上监听,但每次启动时都会分配一个不同的端口。我该如何改变这一点?
这是我在Visual Studio中的ASP.NET核心Web服务器的输出后,我开始和停止服务器的3倍:
WebApi> Hosting environment: Development
WebApi> Content root path: C:\Code\Work\webcoreapi\WebApi
WebApi> Now listening on: http://localhost:25626
WebApi> Application started. Press Ctrl+C to shut down.
WebApi> Hosting environment: Development
WebApi> Content root path: C:\Code\Work\webcoreapi\WebApi
WebApi> Now listening on: http://localhost:22130
WebApi> Application started. Press Ctrl+C to shut down.
WebApi> Hosting environment: Development
WebApi> Content root path: C:\Code\Work\webcoreapi\WebApi
WebApi> Now listening on: http://localhost:22405
WebApi> Application started. Press Ctrl+C to shut down.
如果我通过dotnet run
运行在命令行同一应用程序将同时启动应用程序并按照预期每次收听localhost:5000
。
所以它必须做一些与我的Visual Studio配置,但我找不到它。这里是我的launchSettings.json
文件:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5000/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchUrl": "http://localhost:5000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
所以我想一切正确配置。我知道Visual Studio会尝试找到一个开放的端口,如果默认的端口不可用,但我已经检查过。当我在VS中启动服务器时,端口5000始终可以自由使用。
有没有人有提示如何让VS始终在5000上启动?
我使用Visual Studio 2017年社区(版本15.3.5)
您可以使用Jexus Manager打印出相关设置,https://www.jexusmanager.com/en/latest/tutorials/vs-diagnostics.html –