Home All Groups Group Topic Archive Search About

Session Variables in asp.net

Author
25 Jun 2009 4:25 PM
Mark Brown
I've encountered a problem that is very frustrating.  I'm working on a web
page and storing data in a session variable.  I've done this in many other
programs done with  with no problems, so hitting this snag took me by
surprise.  I'm using VS 2008.

In my current project however, the session variable I'm trying to use seems
to disappear after clicking a button.  I could run my query again, but
that's why I use session variables to reduce hits to the database.

If I access the session variable before causing the page to reload by
clicking on a button, I can retrieve the value.

What should I look for?

Thanks,
Mark

Author
26 Jun 2009 7:54 AM
Angel_J._Hernández_M.
Session variables will exist as long as the session does. What you just
mentioned doesn't make much sense, can you please provide your code so we
can help you?

Regards,



--
Angel J. Hernández M
MCP,MCAD,MCSD,MCDBA
Microsoft MVP
http://msmvps.com/blogs/angelhernandez
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
http://www.customware.net
Tecnical Solutions Architect





Show quoteHide quote
"Mark Brown" <mbr***@echd.org> wrote in message
news:#nkNLGb9JHA.1248@TK2MSFTNGP04.phx.gbl...
> I've encountered a problem that is very frustrating.  I'm working on a web
> page and storing data in a session variable.  I've done this in many other
> programs done with  with no problems, so hitting this snag took me by
> surprise.  I'm using VS 2008.
>
> In my current project however, the session variable I'm trying to use
> seems to disappear after clicking a button.  I could run my query again,
> but that's why I use session variables to reduce hits to the database.
>
> If I access the session variable before causing the page to reload by
> clicking on a button, I can retrieve the value.
>
> What should I look for?
>
> Thanks,
> Mark
>
>
Author
9 Jul 2009 8:26 PM
Michael D. Ober
There is another possibility that involves session variables and connections
to legacy systems.  IIS doesn't guarantee thread identity between pages.  If
your session variable creates a link to a mainframe it is possible that the
link is being lost between pages.

Mike Ober.

Show quoteHide quote
"Angel J. Hernández M." <angeljesu***@hotmail.com> wrote in message
news:529447A2-3F5A-49A7-BAFA-2A5B93179DE5@microsoft.com...
> Session variables will exist as long as the session does. What you just
> mentioned doesn't make much sense, can you please provide your code so we
> can help you?
>
> Regards,
>
>
>
> --
> Angel J. Hernández M
> MCP,MCAD,MCSD,MCDBA
> Microsoft MVP
> http://msmvps.com/blogs/angelhernandez
> *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> http://www.customware.net
> Tecnical Solutions Architect
>
>
>
>
>
> "Mark Brown" <mbr***@echd.org> wrote in message
> news:#nkNLGb9JHA.1248@TK2MSFTNGP04.phx.gbl...
>> I've encountered a problem that is very frustrating.  I'm working on a
>> web page and storing data in a session variable.  I've done this in many
>> other programs done with  with no problems, so hitting this snag took me
>> by surprise.  I'm using VS 2008.
>>
>> In my current project however, the session variable I'm trying to use
>> seems to disappear after clicking a button.  I could run my query again,
>> but that's why I use session variables to reduce hits to the database.
>>
>> If I access the session variable before causing the page to reload by
>> clicking on a button, I can retrieve the value.
>>
>> What should I look for?
>>
>> Thanks,
>> Mark
>>
>>
>
Author
26 Jun 2009 9:29 AM
Brian Cryer
Show quote Hide quote
"Mark Brown" <mbr***@echd.org> wrote in message
news:%23nkNLGb9JHA.1248@TK2MSFTNGP04.phx.gbl...
> I've encountered a problem that is very frustrating.  I'm working on a web
> page and storing data in a session variable.  I've done this in many other
> programs done with  with no problems, so hitting this snag took me by
> surprise.  I'm using VS 2008.
>
> In my current project however, the session variable I'm trying to use
> seems to disappear after clicking a button.  I could run my query again,
> but that's why I use session variables to reduce hits to the database.
>
> If I access the session variable before causing the page to reload by
> clicking on a button, I can retrieve the value.
>
> What should I look for?

Two thoughts:

1. That you are not overwriting the session variable in some other part of
your code. I'd be inclined to but a breakpoint in "Page_Unload" and see if
the session variable is still defined there, that will give you a guide
whether its something in your code before the Page_Unload or when the next
page is loaded.

2. Less likely, but are you generating files or folders (in your www root)
or doing anything else which might cause the worker process to recycle? If
so then this might explain the situation if all your session data was being
lost. (Solution being to switch away from in-proc.)
--
Brian Cryer
www.cryer.co.uk/brian
Author
30 Jun 2009 5:30 PM
Raja Venkatesh
One possible reason is you have designed the application roles and user
session and session is created single user level.  So different hits could
come into IIS from different user ID.  So the session will be different.  If
you want to keep session variable available for all users, use application
level session.
--
RV


Show quoteHide quote
"Brian Cryer" wrote:

> "Mark Brown" <mbr***@echd.org> wrote in message
> news:%23nkNLGb9JHA.1248@TK2MSFTNGP04.phx.gbl...
> > I've encountered a problem that is very frustrating.  I'm working on a web
> > page and storing data in a session variable.  I've done this in many other
> > programs done with  with no problems, so hitting this snag took me by
> > surprise.  I'm using VS 2008.
> >
> > In my current project however, the session variable I'm trying to use
> > seems to disappear after clicking a button.  I could run my query again,
> > but that's why I use session variables to reduce hits to the database.
> >
> > If I access the session variable before causing the page to reload by
> > clicking on a button, I can retrieve the value.
> >
> > What should I look for?
>
> Two thoughts:
>
> 1. That you are not overwriting the session variable in some other part of
> your code. I'd be inclined to but a breakpoint in "Page_Unload" and see if
> the session variable is still defined there, that will give you a guide
> whether its something in your code before the Page_Unload or when the next
> page is loaded.
>
> 2. Less likely, but are you generating files or folders (in your www root)
> or doing anything else which might cause the worker process to recycle? If
> so then this might explain the situation if all your session data was being
> lost. (Solution being to switch away from in-proc.)
> --
> Brian Cryer
> www.cryer.co.uk/brian
>
>