How to Get Error Details of an ASP.NET 5 app deployed on Azure Websites?

后端 未结 10 1852
执笔经年
执笔经年 2020-12-05 02:23

I have an ASP.NET 5 solution with a website and several project libraries. I\'m using MVC 6 and Entity Framework 7. Locally the app is working fine and until today it was wo

相关标签:
10条回答
  • 2020-12-05 02:39

    I had the same issue and spent a lot of time trying to dig into error logs, etc. (all of the other solutions given above). None of them giving any clue of what's gone wrong.

    What I did that helped me finally see the error was to simply try to publish to a local IIS (after all azure web-app runs your dnx on IIS internally).

    I could then immediately see that there are error when IIS tries to compile the source. (in my case was some malformed nuget package).

    So in short:

    Recreate what happens on azure web-app by publishing to local IIS.

    0 讨论(0)
  • 2020-12-05 02:40

    Errors that occur in startup in an ASPNET5 application are really hard to track down when running the app in Azure (at least with beta 3). Hopefully they find a way to improve the experience. I had to resort to stripping my startup down to the bare bones and then adding code line by line until the failure happened (in my case, it was a missing environment variable).

    I've also used code like this (for debugging only) which might help depending on where the error is happening:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env )
        {           
            try
            {                       
                // Add MVC to the request pipeline.
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller}/{action}/{id?}"
                       );
                });
            }
    
    //exceptions in startup are really bad when running in azure, all you will get is an internal server error
    //this code will write the exception message to the browser instead.  Only use for debugging!!!
    
          catch (Exception ex)          
          {
                app.Run(async context =>
                {
                    context.Response.ContentType = "text/plain";
                    await context.Response.WriteAsync(ex.Message);
                });
            }
        }
    

    Update 10/27/2016 A lot has changed since my original answer. The latest guidance is posted here:

    https://docs.asp.net/en/latest/fundamentals/hosting.html

    So, add:

    .CaptureStartupErrors(true) and .UseSetting(WebHostDefaults.DetailedErrorsKey, "true") on your WebHostBuilder like so:

     var host = new WebHostBuilder()
                .CaptureStartupErrors(true)
                .UseSetting(WebHostDefaults.DetailedErrorsKey, "true")
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();
    
    0 讨论(0)
  • 2020-12-05 02:43

    Have you checked in the eventlog.xml file? It's in the D:\home\LogFiles directory. You can view it from your app's Kudu site, or use the Azure Websites Event Viewer extension.

    0 讨论(0)
  • 2020-12-05 02:49

    Did you try using Remote Debugging the Azure Webapp ? Chances are there is some exception happening which is responsible for this and if you watch your DEBUG OUTPUT window, you may be able to see which exception is happening and then change Visual Studio settings to break on that exception to see where it is happening. check this article to understand how to remote debug - http://blogs.msdn.com/b/webdev/archive/2013/11/05/remote-debugging-a-window-azure-web-site-with-visual-studio-2013.aspx

    0 讨论(0)
提交回复
热议问题