How to get error details on Azure Web site

岁酱吖の 提交于 2019-11-30 02:58:44

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

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());*
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!