How to get error details on Azure Web site
-
26-07-2021 - |
Domanda
I'm new to Azure. Does anybody know how get detailed error message on website deployed to Azure web?
I added SimpleMembership
to website and now Registration and Login (Post) are showing
Sorry, an error occurred while processing your request.
I'm connecting to DB on my home computer (no problem with connection).
LogFiles
folder on azure ftp server has some files but I don't see how to use this information. I wish I can get YellowScreen on azure...
Soluzione
You have two options:
First, you can turn off custom errors in your web config. This is the quick-and-dirty approach but it will at least get you the information you are looking for. Just be sure to turn custom errors back on when you are done. NOTE: This method will display your stacktrace to the entire world.
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
Second, you can remote desktop into your deployed machine, go to IIS Manager, and Browse to your site. Once you are there, reproduce the error and you will get the yellow screen of death you are looking for. For this to work, you will have to Enable Detailed Errors
Altri suggerimenti
Create a table in db where you will store you error logs, I'm using EF and table called Logs.
Create a class:
public class MyAppExceptionFilter : IExceptionFilter
{
private MyApp.Models.ApplicationDbContext db = new Models.ApplicationDbContext();
public void OnException(ExceptionContext context)
{
Exception ex = context.Exception;
Log log = new Log();
log.DateTime = DateTime.Now;
log.LogText = "Exception happened, text:" + ex.Message;
try
{
log.LogText +="User details:"+context.HttpContext.User.Identity.Name;
}
catch
{
log.LogText += "User details:none";
}
db.Logs.Add(log);
db.SaveChanges();
}
}
In FilterConfig.cs in App_Start folder add:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
*filters.Add(new MyAppExceptionFilter());*
}
You can also get the same diagnostic by piping console logs to the cloud shell. Login to azure. Bring up the console...azure CLI.
az webapp log config --name <app-name> --resource-group
myResourceGroup --application-logging filesystem --level information
To start streaming...
az webapp log tail --name <app-name> --resource-group myResourceGroup
Now just refresh the browser for the error.
Ctrl-C back at the CLI will stop streaming.
I picked this up here:Tutorial: Build an ASP.NET Core and Azure SQL Database app in Azure App Service