Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm new with asp.net and i have a project that i need to review and evaluate.
I have noticed that the code contains the statement:

session.contents("value name")

When i searched about this statement i understood that this statement saves a value on the server and can be returned whenever the code call it again. am i right?

I have two questions here:
1- This value can not be accessed by another machine right? i mean when different users working on the same application, no conflicting will be occurred among these session values? i know it may be a dummy question but i just want to make sure of my evaluation.

2- When there is no need to pass a value to other pages, isn't local and private variables within the page are better to use?

Can anyone tell me a brief description about the session values and when we should use it and when we shouldn't?

Thanks
Posted

Answer 1) There will be no conflict as session values are served per user. So if there are two users accessing your applications from different machine, this variable will not be shared between them.

Answer 2) You are right. When there is no need to share values, local and private variables on page level are better to use.

You should try to find information about session and application level variables. There are plenty of resources online. Try this one:
http://msdn.microsoft.com/en-us/library/ms524319(v=vs.90).aspx[^]
 
Share this answer
 
Comments
Brainy Girl 3-Jan-13 6:41am    
Thank you very much for your fast and useful answer.
Prasad_Kulkarni 3-Jan-13 6:45am    
Kindly click on green button to 'Accept Solution' if it is really helpful for you.
Zafar Sultan 3-Jan-13 6:50am    
Welcome.
dimpledevani 3-Jan-13 6:45am    
my 5+
Zafar Sultan 3-Jan-13 6:51am    
Thanks.
You got the point.
1) Session variables are stored in session state (there are different support mechanisms for that), and they are meant to be the mean of separating sessions (:)) identified by a session id. In general a session id is a cookie, that is generated by the server, sent to the client, and the client is sending it back with every request. Thus you can store client specific data in it (but not too many). When a session is abandoned from code or it is timed out, the session id and the session state is destroyed, lost forever. But there is a thread related to the sessions, called session hijacking, when an attacker is stealing/guessing the session id of an other client, thus entering hes/her session, and having access to what the other client has. In this context a client can be a named or an anonymous, ad-hoc user.
2) Session variables are used for keeping value across the session. Thus it is a waste of resource to use it for storing something that is necessary during processing of a single request.

But ASP.NET processing pipeline is more complicated than simple CGI (as PHP for example), I suggest you read this article for a deeper view: http://www.west-wind.com/presentations/howaspnetworks/howaspnetworks.asp[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900