Click here to Skip to main content
12,634,982 members (29,256 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
Which is better practice to use session or cookies in your asp.net application.
Posted 27-Nov-12 6:03am
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  
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!
Marcus Kramer 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100