How to get error details on Azure Web site

假装没事ソ 提交于 2019-11-28 23:59:30

问题


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...


回答1:


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




回答2:


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());*
        }


来源:https://stackoverflow.com/questions/13185074/how-to-get-error-details-on-azure-web-site

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