Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 working also on Azure deployed as an Azure Website.

But today after the latest deployment on Azure I got an error 500 like this on the startup (still working fine locally):

enter image description here

I tried to get more details by :

  • using middleware diagnostics
  • adding the customError / httpError settings in the web.config file
  • downloading the DetailedError page generated

It seems that the error/exception is happening during the Startup/Configure step but I'm still getting the generic error page without details. Even the version generated on the server (DetailedErrors folder) I got this:

enter image description here

I enabled the Failed Request Tracing but still no useful information:

enter image description here

Even if I strip down the code in the Startup/Configure and add a try/catch as suggested I got the same error without détails. It seems to be a configuration/compilation issue but hard to debug without any information.

like image 809
MatthieuGD Avatar asked Apr 08 '15 15:04

MatthieuGD


People also ask

How do I check Azure App Service errors?

Log detailed errors To save the error page or failed request tracing for Windows apps in the Azure portal, navigate to your app and select App Service logs. Under Detailed Error Logging or Failed Request Tracing, select On, then select Save. Both types of logs are stored in the App Service file system.

How do I check deployment logs in Azure app?

You can go to your App Service, click 'Activity log' and set the timespan in which you think the deployment might have occurred (with a maximum of 90 days in the past). In Activity log default Timespan is Last 6 hours, you could choose the Timespan you need.

Is .NET 5 supported in Azure?

Published date: 10 March, 2021Azure Functions now supports running production applications in . NET 5, the latest version of . NET. To support .

How do I troubleshoot Azure App Service?

To access App Service diagnostics, navigate to your App Service web app or App Service Environment in the Azure portal. In the left navigation, click on Diagnose and solve problems.


2 Answers

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();
like image 99
NPNelson Avatar answered Oct 19 '22 18:10

NPNelson


In RC1 (as of beta8, perhaps), one should apparently use:

app.UseDeveloperExceptionPage();

.. which apparently only works if app.Properties["host.AppMode"] is "development".

But this didn't work for me. The error message I was getting was specifically "An error occurred while starting the application", I have found that none of the given configurations will resolve this because the error is occurring before the configurations execute.

Somehow, the publish target folder must have gotten corrupted during publish because I found that deleting the entire deployment directory and re-publishing resolved the problem.

Otherwise, here is the reference: http://docs.asp.net/en/latest/fundamentals/diagnostics.html https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling

like image 28
Jon Davis Avatar answered Oct 19 '22 18:10

Jon Davis