HttpCookie. 1. Cookie is used for sharing data across webforms requested by same user/client and the data is stored on client/browse machine. 2. A cookie is a name value pair generated on behalf of a particular client and saved on the client machine. 3. With every request the browser automatically includes all the cookies appropriate to that request . The cookie Name-Value pairs are submitted in the form of request header called “Cookie” and they are saved on the server in the form of CGI environmental variable called as HTTPCookie. 4. Cookies generates on server(added to the response ) are rendered to the browser in a form of response header called “Set_Cookie”. 5. Every response cookie has name ,values , domain , and path , expires and secure attributes. These attributes are used by browse, while deciding whether to include the cookie in the request or not. 6. Note :- Domain , Path, Expires and Secure attributes are not included with a cookie in the request. Type of Cookies: 1. Persistence Cookie :- Cookies which are permanently stored on the client machine in a file . This cookie values are shared by all the browser instances running on that machine. 2. NotPersistence Cookie :- This cookies which are temporarily stored in the browsers memory . These are not shared across browser instance and are also called as Session Cookie.
Notes:- 1. Every browser restricts the size of each cookie (approx to 4 kb) and also the total number of cookies (to 20 ) which is would accept from a given domain. 2. If a cookies added to the response already exists on the client and also its domain and path attributes match to the new cookie, the value of old cookie is overwritten with the value of new cookie.
HTTPSessionState. A session is an object on server having key –value pairs created on the server on behalf of every client. This object is created on the first request from the client and the same object is reused for all subsequent requests by that client. In session key – value pair is of type string – object and hence in session we can store any type of data alike cookies where we can only store strings. Also sessions can store any amount of data and also we can have unlimited numbers key – value pairs. When a new session is created a unique ID is assigned to it and the same is rendered in the response as a non-persistence cookie . With all subsequent requests the browser includes this cookie and asp.net uses it for deciding about which session object to be used for that client’s request. There is time out period defined for every session. The default is 20 minutes . If the time after the last request by the client exceeds the timeout period then these session corresponding to that client is automatically destroyed on the server. Programmatically a session can be destroyed using Session.Abondon() . But the session i.e. variables and its data would be destroyed only in subsequent requests. Sessionn.RemoveAll() removes all keys in the session but the session is not destroyed. Note:- A persistence cookie will share the values across browser instances, whereas as a session does not share its values.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|