我正在嘗試從專案的屬性部分更改默認埠,但我看不到任何選項。
我正在使用帶有 .NET core 6 的 Visual Studio 2022。
uj5u.com熱心網友回復:
埠在端點中定義,有多種方法可以更改它們:
用于開發目的
您可以launchSettings.json在 Properties 檔案夾內的檔案中更改:
{
"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"
}
}
}
}
服務器端點
根檔案夾中有一個檔案appsettings.json,您可以更改與服務器相關的配置,這是 Kestrel 的示例:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5400"
},
"Https": {
"Url": "https://localhost:5401"
}
}
}
}
從命令列
您可以使用--urls引數運行應用程式以指定埠:
dotnet run --urls http://localhost:8076
環境變數
您可以設定ASPNETCORE_URLS.
從源代碼
您可以將 Url 傳遞給Run方法:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run("http://localhost:6054");
或
現在單擊除錯屬性。單擊該啟動組態檔視窗將打開。
現在您可以從這里從應用程式 URL 更改埠。

編輯:添加
您還可以從專案組態檔中更改它,如下所示。

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/380257.html
上一篇:C#編譯器是否將陣列元素與相同型別的變數區別對待?!(System.ArrayTypeMismatchException)
