Cookies, Sessions, and application objects are similar and are collections objects that are used to save data. But the biggest difference between cookies and other objects is that cookies store data on the client's disk, while application and session objects store the data on the server side. Differences in application, section, and cookie objects are shown in the following table:
Object Data Storage Location lifecycle
Application on the Server side of memory. Terminates when IIS shuts down.
The session is stored on the server side of memory. Terminate at set time or offline by user.
Cookies are stored on the client's disk in profile form. Can always exist or be terminated at the time set.
The Cookies object is not subordinate to the Page object, so the usage is different from the application and the Session object. The Cookies object belong to the request object and the response object, each cookie variable is managed by the Cookies object, its correct object class name is HttpCookie Collection. To store a cookie variable, pass the Response object's cookie collection and use the following syntax:
Response.Cookies (Name as String). value= "Information"
To retrieve the cookie, it is a collection of cookies from the request object and returns the specified cookie, and its use syntax looks like this:
Variable =request.cookies (Name as String). Value
The commonly used properties of Cookies are shown in the following table:
Attribute Description Type
All returns all the cookie variables to an array. HttpCookie ()
AllKeys
Returns the names of all cookie variables into an array of string patterns.
String ()
Count returns the number of cookie variables. Integer
Item
Returns the contents of the cookie variable with the cookie variable name or index value.
1. Item (String) as
HttpCookie
2. Item (Index) as
HttpCookie
The common methods of Cookies are as shown in the following table:
Method Description Syntax
Add a new cookie variable into the cookies collection. ADD (ByVal cookie as HttpCookie)
Clear clears all the variables in the cookie set. Cookie Clear ()
Get
Returns a cookie with the cookie variable name or index value
The value of the variable.
1. Get (ByVal index as Integer) as
HttpCookie