I was lucky to redo our exception handling system. While I declare that handling exceptions from the point of view of the application is not what we want, as a rule, it is inevitable when our team is understaffed that we need to push the door, so please do not blaze a globalized solution for handling exceptions: )
I had a good hunt to see what common solutions exist. We are currently using Global.asax with the Application_Error event to execute Server.GetLastError (), which is placed in session state and then redirected to another page where the session data is then retrieved and displayed in humanoid format. The redirect also calls sproc, which will carefully check for error information that: a) is sent by email to developers and b) is viewed from a web page accessible only to developers.
The new way I've seen is to use the IHttpModule interface using the class in App_Code to do something on these lines (this is my quick implementation)
Imports Microsoft.VisualBasic Public Class ErrorModule : Implements IHttpModule Public Sub Dispose() Implements System.Web.IHttpModule.Dispose ' Not used End Sub Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init AddHandler context.Error, AddressOf context_Error End Sub Public Sub context_Error(ByVal sender As Object, ByVal e As EventArgs) Dim ex As Exception = HttpContext.Current.Server.GetLastError ' do something with the error ' call the stored procedure ' redirect the user to the error page HttpContext.Current.Server.ClearError() HttpContext.Current.Response.Redirect("index.htm") End Sub End Class
My question is: what is the advantage of this solution using Global.asax events? Also, what is the best way to transfer data to an error page?
EDIT: the above code works;)
EDIT: Also, how does the HttpModule work behind the scenes? Does it just log an Error event for this particular function when the application starts?
UPDATE:
After much further research, it seems that session data capture is really, really messy when it comes to using the IHttpModule interface. I donβt think that the MS HttpModule has matured enough to be used in our specific scenario - until there are events specific to the session data that it is too dangerous for us.
source share