代码之家  ›  专栏  ›  技术社区  ›  Enderbyte09

ASP。NET Core绝对拒绝在其他端口上托管

  •  0
  • Enderbyte09  · 技术社区  · 11 月前

    我正在运行一个ASP。NET Core 8.0 Web Service应用程序。在我的Windows电脑上,我开发了这个应用程序,并将其发布到arm64,然后将其复制到目标电脑(树莓派)。尽管每个配置文件都要求应用程序托管在端口上 11111 (我想要的),当我在目标计算机上启动应用程序时,会发生以下情况:

    warn: Microsoft.AspNetCore.Server.Kestrel[0]
          Overriding address(es) 'http://*.11111'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
    fail: Microsoft.Extensions.Hosting.Internal.Host[11]
          Hosting failed to start
          System.IO.IOException: Failed to bind to address http://[::]:80: address already in use.
    

    我已经尝试了所有有多重冗余的方法,但似乎无法在11111上主持。

    appsettings.json:

    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft.AspNetCore": "Warning"
        }
      },
      "AllowedHosts": "*",
      "urls": "http://*.11111;http://192.168.1.169:11111;http://localhost:11111;http://<MYDOMAIN>:11111;http://*:11111"
    
    }
    
    

    程序.cs:

    var builder = WebApplication.CreateBuilder(args);
    
    // Add services to the container.
    Constants.LoadConstants();
    builder.WebHost.UseUrls(new string[]
    {
        "http://*.11111",
        "http://192.168.1.169:11111",
        "http://<MYDOMAIN>:11111",
        "http://0.0.0.0:11111",
        "http://*:11111"
    });
    builder.Services.AddControllers().AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.PropertyNamingPolicy = null;
    });
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    app.Urls.Add("http://*.11111");
    app.MapControllers();
    app.Run();
    
    

    整个应用程序中根本没有提到“80”这个名字。非常感谢您的帮助。

    1 回复  |  直到 11 月前
        1
  •  1
  •   MxNbrt    11 月前

    你的应用程序显示

    正在覆盖地址“http://*.11111”

    但是这不是一个有效的url,所以使用默认端口。它应该用冒号而不是句点书写。这句话对我来说很管用:

    builder.WebHost.UseUrls("http://*:11111");
    

    appsettings和应用程序。Urls。不需要添加。