Mus*_*afa 4 visual-studio asp.net-core asp.net-core-webapi
我有一个在 VS 2019 中创建的带有 .net core 3.1 的 Wep Api 项目。为了测试,我将其部署到本地目录并从 doployed 文件夹启动 exe。请参阅使用 Visual Studio 将应用程序部署到本地文件夹。工作正常,但 api 始终监听端口 5000/50001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
Run Code Online (Sandbox Code Playgroud)
在哪里更改端口?项目的Properties/launchSettings.json中的设置似乎没有影响(仅用于从VS调试)?
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5101",
"sslPort": 5101
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"commandLineArgs": "Authority=http://localhost:5100",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Api": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5101;http://localhost:5101"
}
}
}
Run Code Online (Sandbox Code Playgroud)
到本地目录并从 dopleyed 文件夹启动 exe:
这是因为您正在启动 Kestrel 服务器,并且默认情况下它使用5000/5001. 通常,depoly我们使用术语来代替它publish。Deploy意味着将其部署到某个服务器并与 IIS/nginx 交互。whilepublish表示生成可执行文件。
如果要更改端口,可以更改appsettings.{env}.json,添加urls如下:
{
"urls": "http://localhost:8800",
...
Run Code Online (Sandbox Code Playgroud)
或者,如果您想8800动态覆盖,只需传递 by 参数--urls:
yourapp.exe --urls=https://localhost:8822
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8773 次 |
| 最近记录: |