Hello,
Quote:
quote:Originally posted by mega
Why would I need to store it in a session?
|
A browser hits a site. The site creates a unique identifier (ID), allocates some memory on the server (the session), and tags this memory with this ID. The server places this ID in the response header, and this "cookie" is passed back to the client browser. This cookie is timestamped (it will time out in 20 minutes.)
All subsequent requests from the browser to the server contain this ID. The server uses this ID and tries to find the block of memory it belongs to. It find the memory. Hence, the session is still alive, the cookie is given a fresh timestamp (a new 20 minute timeout), and sent back to the browser with the rest of the page.
Browsers that are spawned from this browser share the cookie (they pass the same ID back and forth to the server.) Every request resets the 20 minute timer.
If you go to lunch for 60 minutes, come back, and hit the site, your ID cannot be found by the server, so it creates a new session (and you handle this and make the use login again, etc...) Your session may have expired on the server - and in the simpleist of environments, fired a SessionEnd event, whereby you could have logged this into a database. But, this is the server side, so it has no idea what the client side is or isn't doing.
(Thanks to
us7892)
Quote:
quote:Originally posted by mega
If a user visits my website then each object in my code behind is a unique object, right?
|
yes,
Each page is executed separately, within its own context. Two page executions happening simultaneously are not related in any way apart from their existance within the same application. Only during the execution of one page, in one page's context will the same "current" value in a class' public static variable be visible.
Let me say that you have this:
Public Class MyClass
Public Static MyStaticVariable As Integer = 0
End Class
User A:
MyClass.MyStaticVariable=1
Response.Write(MyClass.MyStaticVariable) 'This prints "1"
User B:
Response.Write(MyClass.MyStaticVariable) 'This prints "0"
(Thanks to
Peter Lanoie)
hope I could make you understood the difference between sessions and global objects.
--------------------------------------------
Mehdi.:)