How to get error details on Azure Web site

前端 未结 2 2066
情歌与酒
情歌与酒 2020-12-28 15:37

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 Regist

相关标签:
2条回答
  • 2020-12-28 15:47

    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());*
            }
    
    0 讨论(0)
  • 2020-12-28 16:08

    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

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