I am trying to add some error handling in a Global.asax file. I am
declaring a session variable within the Application_Error 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 advancePost the code which is failing.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
<bmukulu@.gmail.comwrote in message news:1174846749.292871.264970@.y66g2000hsf.googlegr oups.com...
Quote:
Originally Posted by
Hi,
>
I am trying to add some error handling in a Global.asax file. I am
declaring a session variable within the Application_Error 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
>
On Mar 25, 1:24 pm, "Juan T. Llibre" <nomailrepl...@.nowhere.com>
wrote:
Quote:
Originally Posted by
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 espaol :http://asp.net.do/foros/
===================================
>
>
>
<bmuk...@.gmail.comwrote in messagenews:1174846749.292871.264970@.y66g2000hsf.g ooglegroups.com...
Quote:
Originally Posted by
Hi,
>
Quote:
Originally Posted by
I am trying to add some error handling in a Global.asax file. I am
declaring a session variable within the Application_Error 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?
>
Quote:
Originally Posted by
Thanks in advance- Hide quoted text -
>
- Show quoted text -
Here is the code:
Sub Application_Error(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ex As Exception = Server.GetLastError()
If Not ex.InnerException Is Nothing AndAlso TypeOf
ex.InnerException Is System.IO.FileNotFoundException Then
HttpContext.Current.Session("sExample") = "This is an
example"
End If
End Sub
bmukulu@.gmail.com wrote:
Quote:
Originally Posted by
On Mar 25, 1:24 pm, "Juan T. Llibre" <nomailrepl...@.nowhere.com>
wrote:
Quote:
Originally Posted by
>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 espaol :http://asp.net.do/foros/
>===================================
>>
>>
>>
><bmuk...@.gmail.comwrote in messagenews:1174846749.292871.264970@.y66g2000hsf.g ooglegroups.com...
Quote:
Originally Posted by
>>Hi,
>>I am trying to add some error handling in a Global.asax file. I am
>>declaring a session variable within the Application_Error 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_Error(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ex As Exception = Server.GetLastError()
If Not ex.InnerException Is Nothing AndAlso TypeOf
ex.InnerException Is System.IO.FileNotFoundException Then
HttpContext.Current.Session("sExample") = "This is an
example"
>
End If
>
End Sub
>
You have to check if you have an HttpContext object before you try to
use it. It's not at all certain that the code where the error occurs has
a http context at all.
--
Gran Andersson
_____
http://www.guffa.com
Can you try this and see if it makes a difference ?
Protected Sub Application_Error(sender As [Object], e As EventArgs)
' Get the information about the error
Dim ctxt As HttpContext = HttpContext.Current
Dim except As Exception = ctxt.Server.GetLastError()
Dim errorInfo As String = "<br>Offending URL: " + ctxt.Request.Url.ToString() + "<br>Source: " _
+ except.Source + "<br>Message: " + except.Message + "<br>Stack trace: " + except.StackTrace
ctxt.Response.Write(errorInfo)
' ----------------
' To let the page finish executing we clear the error
' ----------------
ctxt.Server.ClearError()
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.Current.Session Is Nothing Then
Dim ctxt As HttpContext = HttpContext.Current
Dim except As Exception = ctxt.Server.GetLastError()
HttpContext.Current.Session.Add("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 espaol : http://asp.net.do/foros/
===================================
<bmukulu@.gmail.comwrote in message news:1174849512.334478.233980@.n59g2000hsh.googlegr oups.com...
On Mar 25, 1:24 pm, "Juan T. Llibre" <nomailrepl...@.nowhere.com>
wrote:
Quote:
Originally Posted by
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 espaol :http://asp.net.do/foros/
===================================
>
>
>
<bmuk...@.gmail.comwrote in messagenews:1174846749.292871.264970@.y66g2000hsf.g ooglegroups.com...
Quote:
Originally Posted by
Hi,
>
Quote:
Originally Posted by
I am trying to add some error handling in a Global.asax file. I am
declaring a session variable within the Application_Error 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?
>
Quote:
Originally Posted by
Thanks in advance- Hide quoted text -
>
- Show quoted text -
Here is the code:
Sub Application_Error(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ex As Exception = Server.GetLastError()
If Not ex.InnerException Is Nothing AndAlso TypeOf
ex.InnerException Is System.IO.FileNotFoundException Then
HttpContext.Current.Session("sExample") = "This is an
example"
End If
End Sub
Howdy,
You have to call Server.ClearError method after handling Application.OnError
event in order to prevent thread from being aborted (unhandled exception).
Without doing so, ASP.NET runtime assumes exception has not been handled and
stops the execution before session state is updated with chages.
Sub Application_Error(ByVal sender As Object, _
ByVal e As EventArgs)
' Fires when an error occurs
Dim ex As Exception = Server.GetLastError()
If Not ex.InnerException Is Nothing AndAlso _
TypeOf ex.InnerException Is System.IO.FileNotFoundException Then
HttpContext.Current.Session("sExample") = "This is an example"
Server.ClearError()
End If
End Sub
hope this helps
--
Milosz
"bmukulu@.gmail.com" wrote:
Quote:
Originally Posted by
On Mar 25, 1:24 pm, "Juan T. Llibre" <nomailrepl...@.nowhere.com>
wrote:
Quote:
Originally Posted by
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:1174846749.292871.264970@.y66g2000hsf.g ooglegroups.com...
Quote:
Originally Posted by
Hi,
Quote:
Originally Posted by
I am trying to add some error handling in a Global.asax file. I am
declaring a session variable within the Application_Error 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?
Quote:
Originally Posted by
Thanks in advance- Hide quoted text -
- Show quoted text -
>
Here is the code:
Sub Application_Error(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ex As Exception = Server.GetLastError()
If Not ex.InnerException Is Nothing AndAlso TypeOf
ex.InnerException Is System.IO.FileNotFoundException Then
HttpContext.Current.Session("sExample") = "This is an
example"
>
End If
>
End Sub
>
>
Hi Goran,
If HttpContext.Current was null he would get null reference exception. The
problem he described is definitely related to unhandeld exception, that
prevents session state to updated (i tesetd it), therefore he must call
Server.ClearError afterwards.
Best regards
--
Milosz
"G?ran Andersson" wrote:
Quote:
Originally Posted by
bmukulu@.gmail.com wrote:
Quote:
Originally Posted by
On Mar 25, 1:24 pm, "Juan T. Llibre" <nomailrepl...@.nowhere.com>
wrote:
Quote:
Originally Posted by
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:1174846749.292871.264970@.y66g2000hsf.g ooglegroups.com...
>Hi,
>I am trying to add some error handling in a Global.asax file. I am
>declaring a session variable within the Application_Error 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_Error(ByVal sender As Object, ByVal e As
EventArgs)
' Fires when an error occurs
Dim ex As Exception = Server.GetLastError()
If Not ex.InnerException Is Nothing AndAlso TypeOf
ex.InnerException Is System.IO.FileNotFoundException Then
HttpContext.Current.Session("sExample") = "This is an
example"
End If
End Sub
>
You have to check if you have an HttpContext object before you try to
use it. It's not at all certain that the code where the error occurs has
a http context at all.
>
--
G?ran Andersson
_____
http://www.guffa.com
>
Milosz Skalecki [MCAD] wrote:
Quote:
Originally Posted by
Hi Goran,
>
If HttpContext.Current was null he would get null reference exception.
If you read the original post again, you'll see that this is exactly
what he is getting.
Quote:
Originally Posted by
The
problem he described is definitely related to unhandeld exception, that
prevents session state to updated (i tesetd it), therefore he must call
Server.ClearError afterwards.
>
Best regards
--
G?ran Andersson
_____
http://www.guffa.com
Good call Goran, your're right. I thought he could not read the information
already stored- I must have been very sleepy at the time i replied :)
Regards
--
Milosz
"G?ran Andersson" wrote:
Quote:
Originally Posted by
Milosz Skalecki [MCAD] wrote:
Quote:
Originally Posted by
Hi Goran,
If HttpContext.Current was null he would get null reference exception.
>
If you read the original post again, you'll see that this is exactly
what he is getting.
>
Quote:
Originally Posted by
The
problem he described is definitely related to unhandeld exception, that
prevents session state to updated (i tesetd it), therefore he must call
Server.ClearError afterwards.
Best regards
>
--
G?ran Andersson
_____
http://www.guffa.com
>
0 comments:
Post a Comment