Guest User

Untitled

a guest
May 27th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <customErrors mode="On" defaultRedirect="~/Error.aspx"></customErrors>
  2.  
  3. <script RunAt="server">
  4. void Application_Error(object sender, EventArgs e)
  5. {
  6. Exception ex = Server.GetLastError();
  7. if (ex != null && Session != null)
  8. {
  9. ex.Data.Add("ErrorTime", DateTime.Now);
  10. ex.Data.Add("ErrorSession", Session.SessionID);
  11. HttpContext.Current.Cache["LastError"] = ex;
  12. }
  13. }
  14.  
  15. </script>
  16.  
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19. if (IsPostBack) return;
  20.  
  21. if (HttpContext.Current.Cache["LastError"] != null)
  22. {
  23. Exception ex = (Exception)HttpContext.Current.Cache["LastError"];
  24. if (ex.Data["ErrorTime"] != null && ex.Data["ErrorSession"] != null)
  25. if ((DateTime)ex.Data["ErrorTime"] > DateTime.Now.AddSeconds(-30d) && ex.Data["ErrorSession"].ToString() == Session.SessionID)
  26. Label1.Text = ex.InnerException.Message;
  27. }
  28. }
  29.  
  30. Server.Transfer(String.Concat("~/Error.aspx?message=", HttpUtility.UrlEncode(ex.InnerException.Message)))
  31.  
  32. void Application_Error(object sender, EventArgs e)
  33. {
  34. HttpContext.Current.Cache["LastError"] = Server.GetLastError().GetBaseException();
  35. Server.ClearError();
  36. }
  37.  
  38. protected void Page_Load(object sender, EventArgs e)
  39. {
  40. if (IsPostBack) return;
  41.  
  42. if (HttpContext.Current.Cache["LastError"] != null)
  43. {
  44. Exception ex = (Exception)HttpContext.Current.Cache["LastError"];
  45. if (ex != null)
  46. Label1.Text = ex.Message;
  47. }
  48. }
  49.  
  50. Server.ClearError();
Add Comment
Please, Sign In to add comment