Or you could create a global.asax file in your application and put the code there. There is a section especially for “application shutdown” although I am not sure if it will work when your page is redirected. But you can play with it.
i use this piece of code in all my internal application. See example below:
Code:
<%@ Application Language="VB" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
'Dim ex As Exception = Server.GetLastError
'If Not ex.GetType.FullName = "System.Web.HttpException" Then
' Error_Reporting.Report_Error(Server.GetLastError.Message, HttpContext.Current.User.Identity.Name)
'End If
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when an unhandled error occurs
Dim ex As Exception = Server.GetLastError
If Not ex.GetType.FullName = "System.Web.HttpException" Then
Error_Reporting.Report_Error(Server.GetLastError.Message, HttpContext.Current.User.Identity.Name)
End If
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started
' Dim a As New ArrayList
End Sub
Protected Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As System.EventArgs)
'check if user was authenticated
End Sub
</script>