Catching errors in Global.asax

后端 未结 3 959
清歌不尽
清歌不尽 2021-02-07 23:08

I have the following in my Global.aspx which is meant for handling errors:

void Application_Error(object sender, EventArgs e)
{
    Exception exception = Server.         


        
3条回答
  •  臣服心动
    2021-02-07 23:45

    Application_Error block can catch exception anytime between application life cycle.

    Application life cycle is parent of Session life cycle as you can understand there can be many sessions within a single application.

    Thus you may have HttpContext.Current null at certain errors occured before creating session or after expiring of sessions.

    If you want to write session specific error redirects you should check for Null of current HttpContext always.

    You can also use Server.GetLastError to know the error details occured and write your error page redirect through CustomError tag in web.config

    See the following link

    http://weblogs.asp.net/scottgu/archive/2006/08/12/Tip_2F00_Trick_3A00_-Show-Detailed-Error-Messages-to-Developers.aspx

提交回复
热议问题