.NET Core Web Api 错误 -4090 EADDRNOTAVAIL 地址在 Azure 上不可用

Men*_*sur 4 azure .net-core asp.net-core-webapi

我有一个在本地运行良好的 .NET Core 1.1 Web Api 项目。一旦我将它部署到 Azure 上的 AppService,它就不会响应任何 GET 请求——它们都超时了。我有一个开放的 ping 端点,它只返回当前日期和时间,但没有响应。查看日志我看到了这个:

[INF] Azure Web Sites environment detected. Using '"D:\home\ASP.NET\DataProtection-Keys"' as key repository; keys will not be encrypted at rest. (383ad3af)
[WRN] Unable to bind to http://localhost:22676 on the IPv6 loopback interface. (de7f78a0)
System.AggregateException: One or more errors occurred. (Error -4090 EADDRNOTAVAIL address not available) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4090 EADDRNOTAVAIL address not available
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener.CreateListenSocket()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)
   at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
---> (Inner Exception #0) Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -4090 EADDRNOTAVAIL address not available
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.tcp_bind(UvTcpHandle handle, SockAddr& addr, Int32 flags)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener.CreateListenSocket()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)<---
Run Code Online (Sandbox Code Playgroud)

我不确定为什么会发生这种情况以及如何解决它。

编辑:这是 Program.cs

public static void Main(string[] args)
    {
        var configuration = new ConfigurationBuilder()
            .AddEnvironmentVariables()
            .AddCommandLine(args)
            .Build();

        var host = new WebHostBuilder()
            .ConfigureLogging(options => options.AddConsole())
            .ConfigureLogging(options => options.AddDebug())
            .UseConfiguration(configuration)
            .UseIISIntegration()
            .UseKestrel(options =>
            {
                options.ThreadCount = 1;
            })
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
Run Code Online (Sandbox Code Playgroud)

And*_*toy 5

ASP.NET Core 2.0 也有同样的问题。明确指定主机将侦听​​的 URL:

public static IWebHost BuildWebHost(string[] args)
{
    return WebHost
                .CreateDefaultBuilder(args)
                .UseUrls("http://+:22676") // <--add urls
                .UseStartup<Startup>()
                .Build();
}
Run Code Online (Sandbox Code Playgroud)