/ / launchSettings.JSONでNet.Coreアプリケーション用のポートを設定できません - json、asp.net-core

launchSettings.JSON - json、asp.net-coreでNet.Coreアプリケーション用のポートを設定できません

私は編集しました launchSettings.JSON ポートを変更しました。

"Gdb.Blopp": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "http://localhost:4000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

しかし、まだポート5000から始まります。その設定はすべて無視されているのでしょうか、それとも他に何か不足していますか?

回答:

回答№1は4

launchSettings.json F5 / Ctr + F5を押してスタートボタンの横にあるプルダウンメニューからオプションを選択すると、Visual Studioのみが表示されます。

ここに画像の説明を入力

また、あなたは直接それを編集してはいけません launcherSettings.json 代わりにプロジェクトのプロパティを使用して項目を変更します。

この理由の1つは、プロジェクトプロパティを使用して変更すると、Visual StudioはIISエクスプレスファイル( .vs/config/applicationhost.config あなたのソリューションのフォルダ)。

kestrelの使用するポートを変更したい場合は、 .UseUrls("http://0.0.0.0:4000") (それを appsettings.json または hosting.json)in Program.cs.

ハードコーディングを使用したくない場合は、次のようにすることもできます

作成する hosting.json

{
"server": "Microsoft.AspNetCore.Server.Kestrel",
"server.urls": "http://localhost:4000"
}

Program.cs

public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddJsonFile("hosting.json", optional: false)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();

var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}

あなたはコマンドラインでもそれを行うことができます(AddCommandLine ここで重要なのは、 Microsoft.Extensions.Configuration.CommandLine" パッケージ)。

var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();

var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();

それから dotnet run server.urls=http://0.0.0.0:4000.

IIS / IISExpressを実行すると、kestrelポートは次のように決定されます。 UseIISIntegration().


回答№2の場合は0

.NET Core 2.0以降、メンテナンスする必要はありません hosting.json もうアプリの起動を変更することができます。ここに説明されているアプリポートを設定するための組み込みサポートがあります: https://stackoverflow.com/a/49000939/606007