Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 17, 2012 11:52 AM by sameer_khanjit
Dec 10, 2012 11:07 AM|LINK
What is the relationship between Session & Cookies?
Dec 10, 2012 11:13 AM|LINK
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.
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.
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.
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.
Dec 12, 2012 06:43 AM|LINK
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:
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)
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.
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...
Dec 17, 2012 11:52 AM|LINK
Now the question arises that when to use what?
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.
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
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.
Finally remember the following points on your finger-tips: