code_junkie

ASP.NET AJAX WebForms custom error handling question

Nov 13th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. args.set_errorHandled(true);
  2.  
  3. public class CustomUserControl : UserControl
  4. {
  5. public new CustomUserControl
  6. {
  7. this.Error += new EventHandler(Page_Error);
  8. }
  9.  
  10. protected void Page_Error(object source, EventArgs e)
  11. {
  12. Exception exception = HttpContext.Current.Server.GetLastError();
  13. // Message away
  14. }
  15. }
  16.  
  17. protected void Application_Error(object sender, EventArgs e)
  18. {
  19.  
  20. // fired when an unhandled error occurs within the application.
  21. // ..or use an HttpModule instead
  22. }
  23.  
  24. public class UnhandledExceptionModule : IHttpModule
  25. {
  26. #region IHttpModule Members
  27. public void Dispose()
  28. {
  29. }
  30.  
  31. public void Init(HttpApplication app)
  32. {
  33. app.Error += new EventHandler(app_Error);
  34. }
  35.  
  36. protected void app_Error(object sender, EventArgs e)
  37. {
  38. HttpApplication app = sender as HttpApplication;
  39. Exception ex = app.Server.GetLastError().GetBaseException();
Add Comment
Please, Sign In to add comment