我发表了我的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项目的端口?
发布于 2021-05-21 04:50:13
您需要在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的输出如下所示:
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]https://stackoverflow.com/questions/67610456
复制相似问题