Thursday, March 29, 2012

Session varaibles are lost when an error occurs

In VS2003, when debugging (with breakpoints set) a ASP.net web project
(locally), if an error/exception occurs the browser navigates to the "Server
Error" page. After this point it looses all the values stored in the Session
objects, and leads to many other errors, before I must refresh the page and
restart all over again. What the problem can be?
Thanks in advance.Hi,
Before redirecting to the error page the current session is distroyed and a
new session is created. This is the ASP.NET behavior. What you can do is to
catch all unhandled exceptions in the Application_Error from Global file. In
this handler you should clean the error and manually redirect to your custom
error page using Server.Transfer method. This way you prevent the
application from distroying the session.
"So" <.> wrote in message news:O38eKVIUFHA.2712@.TK2MSFTNGP09.phx.gbl...
> In VS2003, when debugging (with breakpoints set) a ASP.net web project
> (locally), if an error/exception occurs the browser navigates to the
"Server
> Error" page. After this point it looses all the values stored in the
Session
> objects, and leads to many other errors, before I must refresh the page
and
> restart all over again. What the problem can be?
> Thanks in advance.
>
Thanks for your reply. Sorry for getting back late.
I tried to do something like this below in global.asax.vb, but I am still
loosing the Session variables. Note that I am not redirecting to any error
page at the moment. What more can be done, and where (on web/docu) can I
read in good details about the ASP.net session handling?
Protected Sub Application_Error(ByVal sender As [Object], ByVal e As
EventArgs)
Dim objErr As Exception =
Server.GetLastError().GetBaseException()
Server.ClearError()
Dim err As String = "<b>Error Caught in Application_Error
event</b><hr><br>" & _
"<br><b>Error in: </b>" &
Request.Url.ToString() & _
"<br><b>Error Message: </b>" &
objErr.Message.ToString() & _
"<br><b>Stack Trace:</b><br>" &
objErr.StackTrace.ToString().Replace("at ", "<br>at ") & _
"<br><a
href='java script:window.location.reload()'>Refresh</a>"
Response.Write(err.ToString())
End Sub
Thanks again for your time.
"Mircea Pleteriu" <mpleteriu@.newsgroup.nospam> schrieb im Newsbeitrag
news:eO46FqJUFHA.228@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Before redirecting to the error page the current session is distroyed and
a
> new session is created. This is the ASP.NET behavior. What you can do is
to
> catch all unhandled exceptions in the Application_Error from Global file.
In
> this handler you should clean the error and manually redirect to your
custom
> error page using Server.Transfer method. This way you prevent the
> application from distroying the session.
> "So" <.> wrote in message news:O38eKVIUFHA.2712@.TK2MSFTNGP09.phx.gbl...
> "Server
> Session
> and
>

0 comments:

Post a Comment