Session : Remains until you close the website(session) or until the time period expires..
Cookies : Remains even after you close the website..so you can use it whenever user re-visit it.
Examples:
session: suppose in flipkart, you add products, so to keep track which products you have put in your cart, all products are stored in session.
Cookie : in the same flipkart, when you close it and re-visit the site, check "The product you recently visit" section, these values are coming from cookies.
Pratik Galoria,
Software Engineer,
iGATE Global Solutions.
ASP maintains session state by providing the client with a unique key assigned to the user when the session begins. This key is stored in an HTTP cookie that the client sends to the server on each request. The server can then read the key from the cookie
and re-inflate the server session state.
Sessions are not cookies, but they can work together to create the illusion of persistence. Persistence is the process of ensuring that the user is connected to the same server ervery time they make a request within the boundaries of a single session. It
is most often implemented using a cookie containing the server session Id, because by this method we can determine where a user's session is currently stored.
HTTP is a stateless protocol, therefore cookies and sessions help the HTTP protocol to maintain state between multiple server requests.
Sessions depend on cookies to work. That is, a session stores its identifier (a large random unique number) in a cookie on the end-user’s machine. Although sessions depend on cookies, sessions will still work even if end-users disable cookies from their
browser settings. This is possible by URL-Rewriting.
Every session will have SessionID. And Session ID is a unique number, server assigns to a specific user, during his visit(session). And defaultely, session ID is attached to a cookie and this cookie will be shared from client to server (and server to client)
during its requests/responses. And server will identify session based on session id which is retrieved from cookie.
And regarding cookieless, if your browser doesnt support cookie or disabled, then cookieless will be used. Since it is Cookieless, asp.net can not create a cookie to save session id. Instead, the session id will be passed in query string...
Viewstate is a hidden fields in an ASP.NET page, contains state of those controls on a page whose “EnableViewstate” property is “true”.
You can also explicitly add values in it, on an ASP.NET page like:
Viewstate.Add( “TotalStudents”, “87″ );
Viewstate should be used when you want to save a value between different roundtrips of a single page as viewstate of a page is not accessible by another page.
Because Viewstate renders with the page, it consumes bandwidth, so be careful to use it in applications to be run on low bandwidth.
2- Session Variable
Session variables are usually the most commonly used.
When a user visits a site, it’s sessions starts and when the user become idle or leave the site, the session ends.
Session variables should be used to save and retrieve user specific information required on multiple pages.
Session variables consumes server memory, so if your may have a huge amount visitors, use session very carefully and instead of put large values in it try to put IDs and references
for more information :- http://support.microsoft.com/kb/307598
3- Application variables
Application variables are shared variables among all users of a web application
Application variables behave like static variables and they are substitute of static variables as static variables are stateless in web applications
Only shared values should be persisted in Application variables, and as soon as they are not in use they should be removed explicitly.
4- Cache
Cache is probably the least used state feature of ASP.NET.
Cache is basically a resource specific state persistence feature, means unlike session it stick with resource instead of user, for instance: pages, controls etc.
Cache should be used or frequently used pages, controls, and data structures
Data cache can be used to cache frequently used list of values e.g. list of products
5- Cookies
Cookies are some values saved in browsers by the website to retrivbbe and use afterwards.
Usually cookies are used to help dynamic websites to identify visitors and retrieve their saved preferences.
Cookies are also used to facilitate auto login by persisting user id in a cookie save in user’s browser.
Because cookies have been saved at client side, they do not create performance issues but may create security issues as they can be hacked from browser.
Finally remember the following points on your finger-tips:
Viewstate is bandwidth hungry
Session variables are memory hungry as per number of users
Applications variables are shared
Cache is memory hungry as per number of resources
Cookies are the least secure
sameer.khanjit@gmail.com
View Blog Click "Mark as Answer" on the post that helped you.
Marked as answer by Amy Peng - MSFT on Dec 18, 2012 03:28 AM
shivani.gupt...
Participant
867 Points
312 Posts
Session & Cookies
Dec 10, 2012 11:07 AM|LINK
What is the relationship between Session & Cookies?
My Blog: http://shivaniaspnet.blogspot.in
jagjot
Contributor
2648 Points
1229 Posts
Re: Session & Cookies
Dec 10, 2012 11:13 AM|LINK
Difference http://php.about.com/od/learnphp/qt/session_cookie.htm
M.Sc, MIEEE, MCP, CCNA
shivani.gupt...
Participant
867 Points
312 Posts
Re: Session & Cookies
Dec 10, 2012 11:15 AM|LINK
Thanks for quick reply, but my question is not on difference... I want to know the relationship between them.
My Blog: http://shivaniaspnet.blogspot.in
pratik_galor...
Participant
1483 Points
330 Posts
Re: Session & Cookies
Dec 10, 2012 11:17 AM|LINK
Both can contain values. but the different is:
Session : Remains until you close the website(session) or until the time period expires..
Cookies : Remains even after you close the website..so you can use it whenever user re-visit it.
Examples:
session: suppose in flipkart, you add products, so to keep track which products you have put in your cart, all products are stored in session.
Cookie : in the same flipkart, when you close it and re-visit the site, check "The product you recently visit" section, these values are coming from cookies.
Software Engineer,
iGATE Global Solutions.
pratik_galoria@yahoo.co.in
+91-8905195943
jagjot
Contributor
2648 Points
1229 Posts
Re: Session & Cookies
Dec 10, 2012 11:18 AM|LINK
Hope this might help...
ASP maintains session state by providing the client with a unique key assigned to the user when the session begins. This key is stored in an HTTP cookie that the client sends to the server on each request. The server can then read the key from the cookie and re-inflate the server session state.
http://msdn.microsoft.com/en-us/library/ms972429.aspx
M.Sc, MIEEE, MCP, CCNA
Amy Peng - M...
Star
10110 Points
954 Posts
Microsoft
Re: Session & Cookies
Dec 12, 2012 06:43 AM|LINK
Hi shivani.gupta,
Sessions are not cookies, but they can work together to create the illusion of persistence. Persistence is the process of ensuring that the user is connected to the same server ervery time they make a request within the boundaries of a single session. It is most often implemented using a cookie containing the server session Id, because by this method we can determine where a user's session is currently stored.
Hope the following article can help you: http://aspadvice.com/blogs/kumarr/archive/2005/06/21/2681.aspx .
Regards,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store
Anil Srivast...
Member
442 Points
292 Posts
Re: Session & Cookies
Dec 12, 2012 06:57 AM|LINK
sessions are created at server side to identify client since http is stateless protocol
while on the other hand cookies are stored at client browers
cookies-session work togeether(client server)
Naved Hasan ...
Participant
1005 Points
212 Posts
Re: Session & Cookies
Dec 14, 2012 04:31 AM|LINK
HTTP is a stateless protocol, therefore cookies and sessions help the HTTP protocol to maintain state between multiple server requests.
Sessions depend on cookies to work. That is, a session stores its identifier (a large random unique number) in a cookie on the end-user’s machine. Although sessions depend on cookies, sessions will still work even if end-users disable cookies from their browser settings. This is possible by URL-Rewriting.
Nasir Hussai...
Participant
1205 Points
570 Posts
Re: Session & Cookies
Dec 14, 2012 12:03 PM|LINK
Every session will have SessionID. And Session ID is a unique number, server assigns to a specific user, during his visit(session). And defaultely, session ID is attached to a cookie and this cookie will be shared from client to server (and server to client) during its requests/responses. And server will identify session based on session id which is retrieved from cookie.
And regarding cookieless, if your browser doesnt support cookie or disabled, then cookieless will be used. Since it is Cookieless, asp.net can not create a cookie to save session id. Instead, the session id will be passed in query string...
http://forums.asp.net/t/1466982.aspx/1?Does+Session+use+Cookies+
sameer_khanj...
Contributor
7056 Points
1376 Posts
Re: Session & Cookies
Dec 17, 2012 11:52 AM|LINK
Now the question arises that when to use what?
1- Viewstate
Viewstate is a hidden fields in an ASP.NET page, contains state of those controls on a page whose “EnableViewstate” property is “true”.
You can also explicitly add values in it, on an ASP.NET page like:
Viewstate.Add( “TotalStudents”, “87″ );
Viewstate should be used when you want to save a value between different roundtrips of a single page as viewstate of a page is not accessible by another page.
Because Viewstate renders with the page, it consumes bandwidth, so be careful to use it in applications to be run on low bandwidth.
2- Session Variable
Session variables are usually the most commonly used.
When a user visits a site, it’s sessions starts and when the user become idle or leave the site, the session ends.
Session variables should be used to save and retrieve user specific information required on multiple pages.
Session variables consumes server memory, so if your may have a huge amount visitors, use session very carefully and instead of put large values in it try to put IDs and references
for more information :- http://support.microsoft.com/kb/307598
3- Application variables
Application variables are shared variables among all users of a web application
Application variables behave like static variables and they are substitute of static variables as static variables are stateless in web applications
Only shared values should be persisted in Application variables, and as soon as they are not in use they should be removed explicitly.
4- Cache
Cache is probably the least used state feature of ASP.NET.
Cache is basically a resource specific state persistence feature, means unlike session it stick with resource instead of user, for instance: pages, controls etc.
Cache should be used or frequently used pages, controls, and data structures
Data cache can be used to cache frequently used list of values e.g. list of products
5- Cookies
Cookies are some values saved in browsers by the website to retrivbbe and use afterwards.
Usually cookies are used to help dynamic websites to identify visitors and retrieve their saved preferences.
Cookies are also used to facilitate auto login by persisting user id in a cookie save in user’s browser.
Because cookies have been saved at client side, they do not create performance issues but may create security issues as they can be hacked from browser.
Finally remember the following points on your finger-tips:
sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.