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

Session Variable vs Cookie

P: n/a
Are Session variables the same as a cookie? In reading a couple of pages I
got from searches, I don't get the difference. Basically, I am currently
using simple session variables (e.g. Session("UserName") =
txtLastName.Text). I think they are expiring for some users (longer
sessions?) and I need to be able to set the expiration to something like
Now() plus 2 hours.

What is the right way to do this?

Wayne
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Nope: Session and cookies are not the same thing. A cookie is a text file
that lives on the user's computer. Session is typically the Web server's
memory and exists for 20 minutes by default. Session can be a lot more than
that, though. You can accomplish what you need to in a variety of ways, but
it might be easiest for you to go with cookies. Read up in the online help
on cookies - how to create them, set expiration time, etc...

K
"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:ee**************@TK2MSFTNGP12.phx.gbl...
Are Session variables the same as a cookie? In reading a couple of pages I
got from searches, I don't get the difference. Basically, I am currently
using simple session variables (e.g. Session("UserName") =
txtLastName.Text). I think they are expiring for some users (longer
sessions?) and I need to be able to set the expiration to something like
Now() plus 2 hours.

What is the right way to do this?

Wayne

Nov 18 '05 #2

P: n/a
Sessions are not really cookies. Basically, session variables are kept in
memory on the server (or through another method such as a database). They
set a cookie on the browser with information to identify exactly what
session the browser is part of. Sessions are usually kept short so that the
server can then close them out and release their resources frequently. That
way, you don't end up with hundrends of sessions active that actually don't
have any users doing anything (sessions don't close when someone browses to
another web site). For things like login information, shorter sessions are
good because if a user leaves their computer and someone else walks up, the
window of opportunity for such an error is reduced. You may want to see what
is useful to put into cookies if you need to keep good control over the time
a value is stored for without eating up tons of server resources. You may
also want to look at ASP.Net's forms authentication features as it also has
a sliding expiration for user information. In other word, the timeout is
refreshed whenever the user grabs another page on the site.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Wayne Wengert" <wa***************@wengert.com> wrote in message
news:ee**************@TK2MSFTNGP12.phx.gbl...
Are Session variables the same as a cookie? In reading a couple of pages I
got from searches, I don't get the difference. Basically, I am currently
using simple session variables (e.g. Session("UserName") =
txtLastName.Text). I think they are expiring for some users (longer
sessions?) and I need to be able to set the expiration to something like
Now() plus 2 hours.

What is the right way to do this?

Wayne

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.