Session Variable vs Cookie

W

Wayne Wengert

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
 
K

Ketchup Please

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
 
M

Mark Fitzpatrick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top