c# - 如何解决 "Failed to bind to address http://127.0.0.1:5000: address already in use."

标签 c# asp.net azure asp.net-core

我使用 Visual Studio 创建了一个 Asp.Net Core 应用程序,并使用 VS 的发布选项在我的 Azure 帐户上发布我的应用程序。

发布后,我使用该链接访问我的网站,但收到“HTTP 错误 500.30 - ASP.NET Core 应用程序无法启动”

我转到 Azure 中的控制台手动启动我的应用程序并了解有关该问题的更多详细信息,然后我得到了这个。 error on console

不太确定如何解决我的端口的这个问题

下面是program.cs中的代码

var connectionString = builder.Configuration.GetConnectionString("LocalConnection");
builder.Services.AddDbContext<LotharDataBaseContext>(options =>
    options.UseSqlServer(connectionString));

builder.Services.AddControllersWithViews();

builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
   .AddNegotiate();

builder.Services.AddAuthorization(options =>
{
    // By default, all incoming requests will be authorized according to the default policy.
    options.FallbackPolicy = options.DefaultPolicy;
});
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

最佳答案

通过你的截图,我看到了Kestrel,所以我想,你创建的web应用程序应该在linux平台上。屏幕截图上的端口占用是预期行为,它不应该是根本原因。由于该站点已经在运行,并且您手动命令它重新启动,因此应该会出现此错误。

我建议您先提供您的 Program.cs 文件,我们需要查看 UseUrls 或 UseKestrel 的代码。

如何在启动webapp时检查日志:

  1. 打开您的 kudu 网站,网址应为 https://your_app_name.scm.azurewebsites.net

  2. 打开 newui,https://your_app_name.scm.azurewebsites.net/newui

  3. 步骤:

enter image description here

enter image description here

enter image description here

  • 在这个default_docker.log文件中,我们将得到有用的消息。
  • 您可以尝试的步骤:

    1. 尝试添加.UseIIS,我们知道您的平台是linux。

      Kestrel address binding errors in azure app service

    2. 删除 .UseUrls(),并重新部署您的网络应用。

    关于c# - 如何解决 "Failed to bind to address http://127.0.0.1:5000: address already in use.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71592915/

    相关文章:

    c# - 方法推断不适用于方法组

    c# - 使用正则表达式匹配和拆分字符串

    c# - 值不能为空 - 应用程序管理器

    asp.net - 如何使用resxresourcewriter写所有三个值?

    C#、xunit、fscheck,使用自定义生成器或约束随机字符串编写基于简单属性的测试

    c# - 如何抛出异常以强制消息进入 NServiceBus 中的错误队列

    java - 如何在本地环境中自动启动Azure Function?

    python - 使用 Azure CLI 获取客户端 IP - Dockerized nginx+Flask+Gunicorn

    c# - 使用 WCF、Windows Phone 7 和 ASP.Net

    c# - 功能管理、功能切换、功能标志不适用于 Azure 应用程序配置存储