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.GetBaseException
CommonFunctions.WriteOutException("C:\Error.Log", ex, Request.QueryString.ToString, Request.Url.ToString _
, Request.UserHostAddress.ToString, HttpContext.Current.Server.MachineName, HttpContext.Current.Request.UrlReferrer.OriginalString)
Dim sbEmail As New StringBuilder
If ex.Message.Trim <> "" Then
' Build the error text
sbEmail.Append("<div style='color:Navy;font:normal normal bold 12pt Palatino Linotype;'>An error has occurred on the " & ConfigurationManager.AppSettings("ApplicationName") & " Site.</div><br/><br/>")
If Not HttpContext.Current.Request.Url Is Nothing Then
sbEmail.Append("<div style='color:black;font:normal normal normal 10pt Palatino Linotype;'><b>The error occurred in: </b> " & HttpContext.Current.Request.Url.ToString & "</div>")
End If
sbEmail.Append("<div style='color:black;font:normal normal normal 10pt Palatino Linotype;'><b>The Client's IP is: </b><i>" & Request.UserHostAddress.ToString & "</i></div>")
sbEmail.Append("<div style='color:black;font:normal normal normal 10pt Palatino Linotype;'><b>The Web Server is: </b><i>" & HttpContext.Current.Server.MachineName & "</i></div>")
sbEmail.Append("<div style='color:black;font:normal normal normal 10pt Palatino Linotype;'><b>The Previous Page was: </b><i>" & HttpContext.Current.Request.UrlReferrer.OriginalString & "</i></div><br/>")
If Not ex.Message Is Nothing Then
sbEmail.Append("<div style='color:black;font:normal normal normal 10pt Palatino Linotype;'><b>The message was: </b><i>" & ex.Message.ToString & "</i></div><br/>")
End If
If Not ex.StackTrace Is Nothing Then
sbEmail.Append("<div style='color:Maroon;font:normal normal normal 10pt Palatino Linotype;'><b>The stack trace was: </b> " & ex.StackTrace.ToString.Replace("at ", "<br/>at ") & "</div><br/>")
End If
' send the email
CommonFunctions.SendEmail("mailbox@server.com", "Error", "tomailbox@server.com" _
, "An error has occurred on the " & ConfigurationManager.AppSettings("ApplicationName") & " Site", sbEmail.ToString _
, Net.Mail.MailPriority.High)
End If
'Server.Transfer("GeneralError.aspx", True)
'Server.ClearError()
'System.Diagnostics.EventLog.WriteEntry("HWC Web Application", ErrMsg, Diagnostics.EventLogEntryType.Error)
'response.Redirect("HWC_Error.aspx")
End Sub