【问题标题】:How can I change the port for a published Blazor Server project?如何更改已发布 Blazor Server 项目的端口?
【发布时间】:2021-08-09 02:55:33
【问题描述】:

我发布了我的 Blazor 项目。然后,当我通过“dotnet myapp.dll”从命令行运行它时,会出现以下错误:

crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel. System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.

我已经更改了 launchsettings.json 中的端口,但这没有任何效果。它仍然使用端口 5000。我可以在哪里更改已编译的 blazor 项目的端口?

【问题讨论】:

    标签: port blazor kestrel


    【解决方案1】:

    您需要在 Program.cs 中添加如下所示的 UseUrls() 方法。在这种情况下,我选择了 8700 端口。

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
                webBuilder.UseStaticWebAssets();
                webBuilder.UseUrls("http://localhost:8700");
            });
    

    然后,当我从命令行运行“dotnet myapp.dll”时,我可以看到 Kestrel 输出如下:

    info: Microsoft.Hosting.Lifetime[0]
          Now listening on: http://localhost:8700
    info: Microsoft.Hosting.Lifetime[0]
          Application started. Press Ctrl+C to shut down.
    info: Microsoft.Hosting.Lifetime[0]
          Hosting environment: Production
    info: Microsoft.Hosting.Lifetime[0]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2018-04-23
      • 1970-01-01
      相关资源
      最近更新 更多