Vis*_*odi 43 c# asp.net-core .net-6.0
我正在尝试从项目的属性部分更改默认端口,但我看不到任何选项。
我正在使用带有 .NET core 6 的 Visual Studio 2022。
Leo*_*Leo 91
端口在端点中定义,有多种方法可以更改它们:
您可以更改launchSettings.jsonProperties 文件夹内的文件:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:22963",
"sslPort": 44349
}
},
"profiles": {
"UrlTest": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7244;http://localhost:5053",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
根文件夹中有一个名为appsettings.jsonwith 的文件,您可以更改服务器相关配置,这是 Kestrel 的示例:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5400"
},
"Https": {
"Url": "https://localhost:5401"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用参数运行应用程序--urls来指定端口:
dotnet run --urls http://localhost:8076
Run Code Online (Sandbox Code Playgroud)
您可以设置ASPNETCORE_URLS.
您可以将 Url 传递给Run方法:
dotnet run --urls http://localhost:8076
Run Code Online (Sandbox Code Playgroud)
或者UseUrl扩展方法:
使用此方法有一个错误,但现在似乎已解决#38185
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run("http://localhost:6054");
Run Code Online (Sandbox Code Playgroud)
有关部署的良好文档: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/ ?view=aspnetcore-6.0
快速解决方案:
在Program.cs:
if (app.Environment.IsDevelopment())
{
app.Run();
}
else
{
app.Run("http://127.0.0.1:8080");
}
Run Code Online (Sandbox Code Playgroud)
您可以从启动配置文件设置中进行设置
单击运行按钮上的下拉菜单。
现在单击调试属性。单击该启动配置文件窗口将打开。
现在您可以从此处更改应用程序 URL 的端口。
编辑:添加
您还可以从项目配置文件中更改它,如下所示。
| 归档时间: |
|
| 查看次数: |
57343 次 |
| 最近记录: |