Basically Cookies are small files which are stored on a user’s computer. It is used to hold a modest amount of data specific to a particular client and website and can be accessed either by the web server or by the client computer.
The Response.Cookies Collection is used for setting the value of collection of the cookies.If the specified cookie does not exist, it is created. If the cookie exists, it takes the new value, and the old value is discarded.
- Name: It specifies the name for the Cookies.
- Key: It is not an optional parameter represents a key value for the cookies.
- Attribute: It specifies the information about the cookies . The attribute parameter can be one of the following.
- Domain: Write-only. It specifies the cookie sent only to requests domain name.
- Expires: It specifies the expiry date of the cookies. If the data is not set, then the cookies will expiry after the session ends.
- HasKeys: Read-only. It specifies whether the cookie contains keys or not.
- Path: Write-only. If specified, the Cookie is sent only to requests to this path. If this attribute is not set, the application path is used.
- Secure: write only. It represents that the cookies is secured.
- Value: It defines a value which is assigned to the key or attribute.
Example 1: Below code illustrates how to create cookies having named “website” and assigned the value “GeeksForGeeks” to it.
Example 2: Below example demonstrate how you can set a value for a cookie and assign values to its attributes.