web-dev-qa-db-ja.com

LaunchSettings.jsonのAsp.NetCore変更URLが機能しない

Webサイトをコンソールアプリケーションとして実行するときに、デフォルトのURL( http:// localhost:50 )を変更したい。

LaunchSettings.jsonを編集しましたが、機能しません...それでもポート5000を使用します:

    {
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:4230/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "website": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "http://localhost:80",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
7
F Andrei

「BuildWebHost」をビルドするときにURLを追加する必要があります。これがお役に立てば幸いです https://github.com/aspnet/KestrelHttpServer/issues/639

以下は、.net Core2.0コンソールアプリケーションで使用するコードです。

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseUrls("http://localhost:5050/")
            .Build();


}

コンソール出力のスクリーンショット

2
Charan

Kestrelを使用すると、hosting.jsonファイルを使用してポートを指定できます。

次のコンテンツを含むhosting.jsonをプロジェクトに追加します。

{
    "server.urls": "http://0.0.0.0:5002" 
}

そしてproject.jsonのpublishOptionsに追加します

"publishOptions": {
"include": [
  "hosting.json"
  ]
}

webHostBuilderを作成するときに、アプリケーションのエントリポイントで「.UseConfiguration(config)」を呼び出します。

        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json", optional: true)
                .Build();

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

            Host.Run();
        }
3
Set

これは既知の問題です(プライベートリポジトリに提出されたため、GitHubの問題を指摘することはできません)。

2
Kiran Challa