N
Nemisis
Hi everyone,
I am trying to create a custom error page, that the user gets shown
when a error has occurred within my website. The code works
perfectly, apart from when an invalid URL is typed in, then i am
unable to pass the exception from the global.asax file to the page via
the sessionstate. Everytime i try to pass something into the
sessionstate i get a error message of 'Object reference not set to an
instance of an object.'
Does anyone know how to get around this error? My code is below
GLOBAL.ASAX PAGE CODE
Sub Application_Error(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ctx As HttpContext = HttpContext.Current
Dim LastException As Exception = ctx.Server.GetLastError
Dim Exception As New ExceptionItem(LastException)
' clear the error
ctx.Server.ClearError()
HttpContext.Current.Session("HELLO") = "AAA"
HttpContext.Current.Session.Add("LastException", Exception)
Me.Response.Redirect("~/Errors/GeneralError.aspx")
End Sub
CUSTOM ERROR PAGE CODE
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim Master As eContrack = Page.Master
Master.SectionTitle = "An error has occurred"
' Session("LastException") is created in the Error event
of global.asax
Dim Exception As ExceptionItem =
CType(Session("LastException"), ExceptionItem)
Exception.Insert()
' See if errors should be sent by email
If
ConfigurationManager.AppSettings("SendErrorByEmail").ToString = "true"
Then
Exception.Email(ConfigurationManager.AppSettings("SendErrorToEmail"),
HelperMethod.GetDns)
End If
End Sub
Thanks in advance
I am trying to create a custom error page, that the user gets shown
when a error has occurred within my website. The code works
perfectly, apart from when an invalid URL is typed in, then i am
unable to pass the exception from the global.asax file to the page via
the sessionstate. Everytime i try to pass something into the
sessionstate i get a error message of 'Object reference not set to an
instance of an object.'
Does anyone know how to get around this error? My code is below
GLOBAL.ASAX PAGE CODE
Sub Application_Error(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ctx As HttpContext = HttpContext.Current
Dim LastException As Exception = ctx.Server.GetLastError
Dim Exception As New ExceptionItem(LastException)
' clear the error
ctx.Server.ClearError()
HttpContext.Current.Session("HELLO") = "AAA"
HttpContext.Current.Session.Add("LastException", Exception)
Me.Response.Redirect("~/Errors/GeneralError.aspx")
End Sub
CUSTOM ERROR PAGE CODE
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim Master As eContrack = Page.Master
Master.SectionTitle = "An error has occurred"
' Session("LastException") is created in the Error event
of global.asax
Dim Exception As ExceptionItem =
CType(Session("LastException"), ExceptionItem)
Exception.Insert()
' See if errors should be sent by email
If
ConfigurationManager.AppSettings("SendErrorByEmail").ToString = "true"
Then
Exception.Email(ConfigurationManager.AppSettings("SendErrorToEmail"),
HelperMethod.GetDns)
End If
End Sub
Thanks in advance