Heroku上的.NET Core应用程序:Web进程无法绑定到$ PORT,该如何解决? [英] .NET Core app on Heroku: Web process failed to bind to $PORT, how to fix?

查看:43
本文介绍了Heroku上的.NET Core应用程序:Web进程无法绑定到$ PORT,该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git将asp.net核心应用程序部署到了heroku.它部署得很好,但是一分钟后由于这个错误而崩溃:

I deployed my asp.net core app to heroku using git. It deployed just fine, but it crushes after a minute with this error:

错误R10(引导超时)-> Web进程在启动后60秒内未能绑定到$ PORT

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

我用Google搜索了它,但是只找到了其他平台的解决方案,而不是.net核心.如何解决此错误?

I googled it, but found only solutions for other platforms, not .net core. How can I fix this error?

我尝试这样做,但是没有用

I tried doing this, but it did not work

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseUrls("http://+:" + System.Environment.GetEnvironmentVariable("PORT"));

    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

推荐答案

这终于让我惊呆了!

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseKestrel(options =>
            {
                options.ListenAnyIP(Int32.Parse(System.Environment.GetEnvironmentVariable("PORT")));
            });

这篇关于Heroku上的.NET Core应用程序:Web进程无法绑定到$ PORT,该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆