ASP.NET Core 1.1 runs fine locally but when publishing to Azure says “An error occurred while starting the application.”

前端 未结 10 1155
情话喂你
情话喂你 2020-12-01 02:42

I\'ve been developing an ASP.NET Core web app, based largely on the MVC template provided in Visual Studio 2017 RC2. It runs just fine in local debug mode, but when I try to

10条回答
  •  既然无缘
    2020-12-01 03:25

    Since many different problems can cause this error page, I can strongly recommend the following in order to determine the root cause quickly and easily, without wrestling Azure (or any server/platform for that matter) to get logs.

    You can enable extremely helpful developer friendly error messages at startup by setting the .UseSetting("detailedErrors", "true") and .CaptureStartupErrors(true) actions in your Program.cs file.

    For ASP.NET Core 1.x

    public static void Main(string[] args)
    {
      var host = new WebHostBuilder()
          .UseKestrel()
          .UseContentRoot(Directory.GetCurrentDirectory())
          .UseSetting("detailedErrors", "true")
          .UseIISIntegration()
          .UseStartup()
          .CaptureStartupErrors(true)
          .Build();
    
      host.Run();
    }
    

    (2018/07) Update for ASP.NET Core 2.1

    public class Program  
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }
    
        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .CaptureStartupErrors(true)
                .UseSetting("detailedErrors", "true")
                .UseStartup()
                .Build();
    }
    
    • These settings should be removed as soon as your troubleshooting is complete so as not to expose your application to malicious attacks.

提交回复
热议问题