By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

session variable getting lost

P: n/a
SAL
Okay, don't bash me to hard for my design on this app, it's my first web app
and it's in production.
My basic design is using Datatables created via the designer with a business
logic class in between the datatable and ObjectDataSources.
In one page I had a Gridview with select enabled. When an row in the grid is
selected, I retrieve the SelectedValue, store the value in a Session
variable and redirect the response to another web page, which, has an
ObjectDataSource on it and a DetailsView. The ObjectDataSource on this page
retrieves the value of the Session variable set from the first page. The
problem is that the Session variable is randomly losing its value.
So, the ObjectDataSource's Business object's SelectMethod accepts a value to
select records by. How do I know that the value is getting lost?
Because no rows are returned as:
dr = dtAdapter.Rows(0)

throws an exception IndexOutOfRange.

My question is, is there some reason that my session variable evaporates
randomly?

Thanks in advance

SAL
Nov 6 '07 #1
Share this Question
Share on Google+
13 Replies


P: n/a
"SAL" <SA*@nospam.nospamwrote in message
news:u5****************@TK2MSFTNGP04.phx.gbl...
My question is, is there some reason that my session variable evaporates
randomly?
No. Session variables will be lost when the Session times out, or when they
are overwritten / removed - does either of these situations apply here...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '07 #2

P: n/a
SAL
Mark, thanks for the reply.
I do not see either of these things applying here. This happened twice this
morning for no apparent reason and then it didn't happen. I have not changed
the time out so it should still be 20 minutes and I am not overwriting them
as far as I can see. I can not reproduce it on my machine.

S

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"SAL" <SA*@nospam.nospamwrote in message
news:u5****************@TK2MSFTNGP04.phx.gbl...
>My question is, is there some reason that my session variable evaporates
randomly?

No. Session variables will be lost when the Session times out, or when
they are overwritten / removed - does either of these situations apply
here...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '07 #3

P: n/a
Hi SAL,

Based on my understanding, you're redirecting to the second page right
after setting the session variable, right? If this is the case, there's no
reason the session variable will be lost due to session timeout. Could you
please double check if the session variable is really lost or it's because
the query that uses the variable to retrieve records from database returns
empty result?

By the way, there's another way to pass variables between pages using
Context.Items and Server.Transfer:

#Famil Jones : Pass Variables Between ASP.NET Pages
http://www.dotnetjunkies.com/WebLog/.../08/11020.aspx
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 7 '07 #4

P: n/a
SAL
Hmmm, thank you for the replies all.
Would it be possible for Walter or someone else to comment on the load that
using the Server.Transfer pattern would place on the server? So, is there an
increased load on the server using this model as compared to using Session
variables?

Thanks
SAL

"SAL" <SA*@nospam.nospamwrote in message
news:u$**************@TK2MSFTNGP02.phx.gbl...
Mark, thanks for the reply.
I do not see either of these things applying here. This happened twice
this morning for no apparent reason and then it didn't happen. I have not
changed the time out so it should still be 20 minutes and I am not
overwriting them as far as I can see. I can not reproduce it on my
machine.

S

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>"SAL" <SA*@nospam.nospamwrote in message
news:u5****************@TK2MSFTNGP04.phx.gbl...
>>My question is, is there some reason that my session variable evaporates
randomly?

No. Session variables will be lost when the Session times out, or when
they are overwritten / removed - does either of these situations apply
here...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Nov 7 '07 #5

P: n/a
Hi SAL,

Regarding difference between Response.Redirect and Server.Transfer, I think
following page is useful for your reference. Each approach has its own pros
and cons.

#Response.Redirect vs Server.Transfer
http://haacked.com/archive/2004/10/0...vertransfer.as
px

Back to the original issue about losing session after Redirect, I think
George's suggestion is quite helpful.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 8 '07 #6

P: n/a
SAL
Thank you for your reply and the article link.
I am currently investigating George's suggestion as well

S

""Walter Wang [MSFT]"" <wa****@online.microsoft.comwrote in message
news:Ra**************@TK2MSFTNGHUB02.phx.gbl...
Hi SAL,

Regarding difference between Response.Redirect and Server.Transfer, I
think
following page is useful for your reference. Each approach has its own
pros
and cons.

#Response.Redirect vs Server.Transfer
http://haacked.com/archive/2004/10/0...vertransfer.as
px

Back to the original issue about losing session after Redirect, I think
George's suggestion is quite helpful.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 8 '07 #7

P: n/a
"SAL" <SA*@nospam.nospamwrote in
news:uF**************@TK2MSFTNGP03.phx.gbl:
Thank you for your reply and the article link.
I am currently investigating George's suggestion as well
Please post back here if (and when) you find the culprit.

I have stopped using sesion variables altogether becuase of
similar issues on a client's server, but am very interested
in what you figure out.

Now my client may well be changing the web.config file
which will cause the application to restart, all the more
reason to not use session varialbes (in my case).

Instead I pass info encrypted in the query string, which
works just fine, the only session variable I use is to
relay error messages to tan error page - if that gets
lost, oh well.

kpg
Nov 8 '07 #8

P: n/a
Hi SAL,

This looks like a normal shutdown, try to use following method to log the
cause and the time it occurs:

#Logging ASP.NET Application Shutdown Events - ScottGu's Blog
http://weblogs.asp.net/scottgu/archi...14/433194.aspx
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 9 '07 #9

P: n/a
Hi SAL,

How's the issue now?

Not directly related, but I think following information might be useful:

#Thomas Marquardt's Blog : ASP.NET File Change Notifications, exactly which
files and directories are monitored?
http://blogs.msdn.com/tmarq/archive/...ange-notificat
ions-exactly-which-files-and-directories-are-monitored.aspx
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 14 '07 #10

P: n/a
SAL
Okay, I did that. Now I'm getting this in the event log:

The description for Event ID ( 0 ) in Source ( .NET Runtime ) cannot be
found. The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event:

_shutDownMessage=HostingEnvironment caused shutdown

_shutDownStack= at System.Environment.GetStackTrace(Exception e, Boolean
needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.HttpRuntime.ShutdownAppDomain()
at System.Web.Hosting.HostingEnvironment.ShutdownThis AppDomainOnce()
at
System.Web.Hosting.HostingEnvironment.InitiateShut downWorkItemCallback(Object
state)
at System.Threading.

Which I really don't understand. Help?

S

""Walter Wang [MSFT]"" <wa****@online.microsoft.comwrote in message
news:OI**************@TK2MSFTNGHUB02.phx.gbl...
Hi SAL,

This looks like a normal shutdown, try to use following method to log the
cause and the time it occurs:

#Logging ASP.NET Application Shutdown Events - ScottGu's Blog
http://weblogs.asp.net/scottgu/archi...14/433194.aspx
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 14 '07 #11

P: n/a
SAL
Hi Walter. It's just as bad as ever and what I don't get is that, I'm not
changing anything when this stuff occurs that I'm aware of. All I'm doing is
redirecting to another page, changing DetailsView states to edit, cancelling
the edit, clicking another menu item and doing the same thing all over again
and it will restart which causes the ID of the item the viewer is using to
be lost in the session variable. And, since the ObjectDataSource is getting
records based on this ID, the app fails with a web page that isn't showing
any data.

S

""Walter Wang [MSFT]"" <wa****@online.microsoft.comwrote in message
news:FR**************@TK2MSFTNGHUB02.phx.gbl...
Hi SAL,

How's the issue now?

Not directly related, but I think following information might be useful:

#Thomas Marquardt's Blog : ASP.NET File Change Notifications, exactly
which
files and directories are monitored?
http://blogs.msdn.com/tmarq/archive/...ange-notificat
ions-exactly-which-files-and-directories-are-monitored.aspx
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 14 '07 #12

P: n/a
SAL
kpg,
what I figured out was the app was getting recycled due to a limit I had set
on virtual memory. There are times when the virtual memory usage jumps up
dramatically and then it pops right back down. The app does not appear to be
leaking memory at this time. So, I unchecked that option in the App pool's
configuration.
I used information garnered from this link to aid me in my quest, although I
haven't completely implemented Peter's Exception Engine.
http://www.eggheadcafe.com/articles/20030816.asp

I placed this code in my Application_Error routine in my Global.asax file:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
' check to see if the ASPNETApplication log exists
Dim b As Boolean
Try
b =
Convert.ToBoolean(ConfigurationManager.AppSettings ("logAppErrors"))
Catch ex As Exception

End Try
If Not b Then Exit Sub

If Not System.Diagnostics.EventLog. _
SourceExists("AnnexationTrackerApplication") Then
System.Diagnostics.EventLog. _
CreateEventSource("AnnexationTrackerApplication",
"Application")
End If
System.Diagnostics.EventLog. _
WriteEntry("AnnexationTrackerApplication",
Server.GetLastError().GetBaseException().Message)

End Sub

The message appeared in the system event log not the application event log.

HTH
S

"kpg*" <no@spam.comwrote in message
news:Xn*******************************@207.46.248. 16...
"SAL" <SA*@nospam.nospamwrote in
news:uF**************@TK2MSFTNGP03.phx.gbl:
>Thank you for your reply and the article link.
I am currently investigating George's suggestion as well

Please post back here if (and when) you find the culprit.

I have stopped using sesion variables altogether becuase of
similar issues on a client's server, but am very interested
in what you figure out.

Now my client may well be changing the web.config file
which will cause the application to restart, all the more
reason to not use session varialbes (in my case).

Instead I pass info encrypted in the query string, which
works just fine, the only session variable I use is to
relay error messages to tan error page - if that gets
lost, oh well.

kpg

Nov 15 '07 #13

P: n/a
There is a problem with losing values in Session Variable. I am
currently troubleshooting as to why. I am working with tabs and all
code is on the same page and my session variables are dropping.
Microsoft acknowledge this is a problem:
http://support.microsoft.com/kb/316148. I am still trying to figure out
why I am losing my session variables. None of the issues mentioned here
or on microsoft have been found to be the culprit.

If anyone knows why, I would like to know.

*** Sent via Developersdex http://www.developersdex.com ***
Mar 28 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.