Click here to Skip to main content
15,398,439 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
What's the difference between session,viewstate and cookies?


with very small EX for each one


thank you
Posted

Hi sara besho,

SESSION Variables are stored on the server, can hold any type of data including references, they are similar to global variables in a windows application and use HTTP cookies to store a key with which to locate user's session variables.

VIEWSTATE Variables are stored in the browser (not as cookies) but in a hidden field in the browser. Also Viewstate can hold only string data or serializable objects.
http://kimphuc.wordpress.com/2009/10/18/the-difference-between-viewstate-sessionstate-cookies-and-cache-in-asp-net/[^]

Also Check out following links to get complete details;
Session & Cookies
1.http://www.allaboutcookies.org/cookies/session-cookies-used-for.html[^]
2.http://php.about.com/od/learnphp/qt/session_cookie.htm[^]

ViewState
3.http://asp.net-tutorials.com/state/viewstate/[^]
4.http://www.w3schools.com/aspnet/aspnet_viewstate.asp[^]
   
v2
Comments
k.Prathap 3-Jan-12 5:39am
   
nice one
Prasad_Kulkarni 3-Jan-12 6:48am
   
thank you
Wendelius 3-Jan-12 15:25pm
   
Good links, my 5.
Prasad_Kulkarni 4-Jan-12 7:05am
   
Thank you soo much sir,
session is server sided object where as view state and cookies are client sided objects
   
Comments
adeezpk 22-Apr-15 4:48am
   
ok
Hi Session stores Data and objects but on server.
Cookies stores only data and stores on client and small amount of data.
ViewState stores data and objects and stores on client side but it stores for only one page, it doesn't work with page to page transfer.
Session["Name"]="Sarvesh";
ViewState["Name"]="Sarvesh";
   
v2
Comments
RaviRanjanKr 3-Jan-12 5:49am
   
[Edited]pre tag is removed from normal text[/Edited]
ASP.NET State Management Overview[^] explains the differences between the three.
   
Comments
Uday P.Singh 3-Jan-12 5:45am
   
5ed :)
Abhinav S 3-Jan-12 5:48am
   
Thanks.
RaviRanjanKr 3-Jan-12 5:49am
   
Nice link, My 5+
Abhinav S 3-Jan-12 6:02am
   
Thanks.
Wendelius 3-Jan-12 15:24pm
   
Really useful link, 5.
Monjurul Habib 4-Jan-12 14:47pm
   
5!
Google is you friend, learn to use it.these question can be easily be answered by google, Read this article:

A Walkthrough to Application State[^]

hope it helps :)
   
Comments
RaviRanjanKr 3-Jan-12 5:49am
   
5+
Uday P.Singh 4-Jan-12 1:35am
   
thank you Ravi :)
Wendelius 3-Jan-12 15:24pm
   
Good link, 5
Uday P.Singh 4-Jan-12 1:35am
   
thank you Mika :)
Monjurul Habib 4-Jan-12 14:47pm
   
5!
session is there for an application where as view state is for page
   

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