Click here to Skip to main content
11,649,582 members (79,573 online)
Rate this: bad
good
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 5:03am
Comments
Sergey Alexandrovich Kryukov at 27-Nov-12 11:05am
   
Totally wrong question. If one thing was definitively better, the other might not even exist...
--SA
Sergey Alexandrovich Kryukov at 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 at 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 at 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 at 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
0 OriginalGriff 354
1 F-ES Sitecore 344
2 Kornfeld Eliyahu Peter 319
3 CPallini 290
4 Maciej Los 269
0 OriginalGriff 1,577
1 Sergey Alexandrovich Kryukov 1,087
2 CPallini 1,015
3 DamithSL 996
4 jyo.net 994


Advertise | Privacy | Mobile
Web04 | 2.8.150804.4 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2015
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