Can you try this and see if it makes a difference ?
Protected Sub Application_Err or(sender As [Object], e As EventArgs)
' Get the information about the error
Dim ctxt As HttpContext = HttpContext.Cur rent
Dim except As Exception = ctxt.Server.Get LastError()
Dim errorInfo As String = "<br>Offend ing URL: " + ctxt.Request.Ur l.ToString() + "<br>Source : " _
+ except.Source + "<br>Messag e: " + except.Message + "<br>Stack trace: " + except.StackTra ce
ctxt.Response.W rite(errorInfo)
' --------------------------------------------------
' To let the page finish executing we clear the error
' --------------------------------------------------
ctxt.Server.Cle arError()
End Sub
--------
Next suggestion :
Without a valid session, you won't be able to store the exception information in it.
Try wrapping the statement in a conditional :
If Not HttpContext.Cur rent.Session Is Nothing Then
Dim ctxt As HttpContext = HttpContext.Cur rent
Dim except As Exception = ctxt.Server.Get LastError()
HttpContext.Cur rent.Session.Ad d("sExample", except)
End If
That will tell you if your Session is valid.
If it is valid, you'll see the Session sExample set with the Exception info.
If it's not valid, Session sExample will be empty.
Juan T. Llibre, asp.net MVP
asp.net faq :
http://asp.net.do/faq/
foros de asp.net, en español :
http://asp.net.do/foros/
=============== =============== =====
<bm*****@gmail. comwrote in message news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
On Mar 25, 1:24 pm, "Juan T. Llibre" <nomailrepl...@ nowhere.com>
wrote:
Post the code which is failing.
Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
=============== =============== =====
<bmuk...@gmail. comwrote in messagenews:11* *************** ******@y66g2000 hsf.googlegroup s.com...
Hi,
I am trying to add some error handling in a Global.asax file. I am
declaring a session variable within the Application_Err or procedure.
However, 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.' Is there any workaround for this? And why am I getting this
error?
Thanks in advance- Hide quoted text -
- Show quoted text -
Here is the code:
Sub Application_Err or(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ex As Exception = Server.GetLastE rror()
If Not ex.InnerExcepti on Is Nothing AndAlso TypeOf
ex.InnerExcepti on Is System.IO.FileN otFoundExceptio n Then
HttpContext.Cur rent.Session("s Example") = "This is an
example"
End If
End Sub