Thursday, March 29, 2012

Session Variable Alternative

I have a few questions for ASP.net in C#. I am using a session variable to
pass the user name from page to page. After a while, the session variable
times out. Is there a way around the time out? Also, what would be a bette
r
way to keep track of the user's name. Will using forms authentication work
better? Right now it is just a debug application, so I didn't turn on Forms
Authentication. I've also never used it. So I don't know what it can
handle, etc...
Thanks -
DrewThe only way to avoid loss of data on a timeout is to use a cookie and store
your values in there, as cookies can persist between sessions. You can
lengthen the timeout of a session in your web.config.
Have a read of this to learn a bit more about sessions....
http://msdn.microsoft.com/library/d...-us/dnaspnet/ht
ml/asp12282000.asp
It doesn't really matter what authentication method you use, if you lose
your session via timeout for example the authentication credentials will go
too.
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"Drew" <Drew@.discussions.microsoft.com> wrote in message
news:9DC1D634-4AA7-4E30-A80E-F7FCEA48D4B2@.microsoft.com...
> I have a few questions for ASP.net in C#. I am using a session variable
to
> pass the user name from page to page. After a while, the session variable
> times out. Is there a way around the time out? Also, what would be a
better
> way to keep track of the user's name. Will using forms authentication
work
> better? Right now it is just a debug application, so I didn't turn on
Forms
> Authentication. I've also never used it. So I don't know what it can
> handle, etc...
> Thanks -
> Drew
"John Timney (Microsoft MVP)" <timneyj@.despammed.com> wrote in message
news:OTG37x%23fEHA.3024@.TK2MSFTNGP10.phx.gbl...

> The only way to avoid loss of data on a timeout is to use a cookie and
store
> your values in there, as cookies can persist between sessions.
Rubbish! If you *really* want to persists data between sessions, store it in
a server-side database.
You can use a StateServer to store session data in RAM on another box (or
another process on the same box.)
This won't help witha timeout though. (It will save you when the aspnet
process recycles itself.)
You can also persist the session to a database if you want. SQL Server only
for 1.1, should be extensible to any DB for 2.0. This will keep the data as
long as you like.
I use forms authentication and store the user name in the Identity object
which is available on every request becasue I keep it in session and pull it
out in Global.asax - AcquireRequest State.
--
Joe Fallon
"Drew" <Drew@.discussions.microsoft.com> wrote in message
news:9DC1D634-4AA7-4E30-A80E-F7FCEA48D4B2@.microsoft.com...
>I have a few questions for ASP.net in C#. I am using a session variable to
> pass the user name from page to page. After a while, the session variable
> times out. Is there a way around the time out? Also, what would be a
> better
> way to keep track of the user's name. Will using forms authentication
> work
> better? Right now it is just a debug application, so I didn't turn on
> Forms
> Authentication. I've also never used it. So I don't know what it can
> handle, etc...
> Thanks -
> Drew
You are correct that you can obviously store data in a server side database,
or a text file even - but it implies that you have information about your
user that identifies them as each new session begins - and in fact a
database to actually hold the values in. Drew could of course also use the
application object byt that itself does not offer persistence between
applications recycling.
If you read the thread - Drew was asking how to persist the username between
sessions in case of timeout. If he is getting the user name at login from a
server side store why would he need to persist it between timeouts at all?
Perhaps I should have said the "easiest way" to persist was with a cookie,
rather than the "only way", as any server side storage between sessions
implies requiring knowledge about the remote user it is by far the most
straightforward approach.
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"Mark Rae" <mark@.mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:ubMuy2#fEHA.3348@.TK2MSFTNGP12.phx.gbl...
> "John Timney (Microsoft MVP)" <timneyj@.despammed.com> wrote in message
> news:OTG37x%23fEHA.3024@.TK2MSFTNGP10.phx.gbl...
>
> store
> Rubbish! If you *really* want to persists data between sessions, store it
in
> a server-side database.
>
Thanks guys - I will try this on Monday and get back with you.
"Joe Fallon" wrote:

> You can use a StateServer to store session data in RAM on another box (or
> another process on the same box.)
> This won't help witha timeout though. (It will save you when the aspnet
> process recycles itself.)
> You can also persist the session to a database if you want. SQL Server onl
y
> for 1.1, should be extensible to any DB for 2.0. This will keep the data a
s
> long as you like.
> I use forms authentication and store the user name in the Identity object
> which is available on every request becasue I keep it in session and pull
it
> out in Global.asax - AcquireRequest State.
> --
> Joe Fallon
>
> "Drew" <Drew@.discussions.microsoft.com> wrote in message
> news:9DC1D634-4AA7-4E30-A80E-F7FCEA48D4B2@.microsoft.com...
>
>

0 comments:

Post a Comment