port - 如何更改已发布的 Blazor Server 项目的端口?

标签 port blazor kestrel

我发布了我的 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 项目的端口?

最佳答案

您需要在 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]

关于port - 如何更改已发布的 Blazor Server 项目的端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67610456/

相关文章:

visual-studio-code - 由于未绑定(bind)断点,在 VS Code 中调试 Blazor WASM 失败

blazor - MudBlazor DataGrid 在嵌套对象类型上的使用

ssl - 使用 Kestrel 在 ASP.NET Core 中实现 SSL

jar - 由于端口原因,Jenkins 不会启动 - 不会接受命令行端口更改或配置文件

crystal-reports - Crystal Reports - 安装到开发机器时被阻止的端口?

java - 如何让Java快速从端口读取字节并将字节存储到文件中?

http - 两个端口号如何同时工作?

blazor - 程序集不包含具有 [JSInvokableAttribute] 的公共(public)可调用方法

azure - 增加在 Azure 上运行的 Dockerized ASP.NET Core 站点的最大上传大小限制?

apache - "Unexpected token H in JSON at position 0"Apache Web 服务器上的 SignalR 核心和 Kestrel