Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Which is better practice to use session or cookies in your asp.net application.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Nov-12 11:05am    
Totally wrong question. If one thing was definitively better, the other might not even exist...
--SA
Sergey Alexandrovich Kryukov 27-Nov-12 11:24am    
And please don't re-post; it cannot help you but can lead to down-voted and abuse reports, which you don't want. I'll remove your next question.

--SA

It's not a question of "better" or "worse" they are used for different purposes.

Session variables are stored at the server, and never leave the server computer. Cookies are stored at the client, and have to make a round trip each time the server wants them.

Which means that session variables expire when the session does (about ten minutes by default) whereas cookies can be maintained almost indefinitely on the client - which may be a good thing (if it's a shopping basket) or a bad thing (if it's a password).
 
Share this answer
 
Comments
Member 9423565 27-Nov-12 11:17am    
Dear sir what you have replied i am abolutly agree on this but the same question is asked in interview from me thats why i want to clear my doubt on this.
OriginalGriff 27-Nov-12 11:24am    
Just because it's asked in an interview does not mean the answer is one or the other - some questions are asked to find out how you think, rather than what you know. I would suspect this is one of those!
fjdiewornncalwe 27-Nov-12 11:28am    
I would suggest that the interviewer wanted an answer such as given by Griff here. They are testing the level of knowledge and confidence you have on the subject. I have always asked at least one misleading question on a basic concept in interviews for the sole purpose of seeing whether the candidate can gracefully handle it.

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