Reputation: 7571
I have a strange problem with my web application. I want to know when I store a value in a session variable like
Session["UserName"] = UserNameTextBox.Text
Will there be a Unique ID associated with this particular Session Variable assignment?
Thanks in anticipation
Upvotes: 0
Views: 389
Reputation: 16419
It will be assigned a unique ID for that user. When a user first visits your site, they will be a assigned a unique "Session ID", this is usually a cookie stored on their web browser, but if you configure it, you can also set the session ID in the URL if they have cookies disabled.
This unique session ID refers to the user's "Session" on the server side. When you use code like you posted, data is added (or updated if it already exists) to the session for that user, and stored while the session is still active so that you can retrieve it later. You can read this variable and write it as much as you want, and it will always be specific to that user.
It is worth noting that Session variables expire. Generally IIS/Web.config sets this limit to 20 minutes. If the user doesn't do anything on your site for 20 minutes (or a time you specify), then to save server resources, that user's session is erased. If you need to keep session active for as long as a user has a page open (say, if the user is filling out a form and it might take longer than 20 minutes), you will need to look into something like AJAX keep-alive requests, which are simple AJAX calls that just tell the server to keep the session alive, and not to delete it after 20 minutes.
Upvotes: 2
Reputation: 1038710
Whatever you store in the session will be available only to the current user. Each user of your site gets a different session id and this id is sent with a cookie so that the server can identify the user. As noted by @Brad Christie at the comments section if cookies are disabled you could configure the session to use hidden fields or send the id as part of the url.
Upvotes: 2