The best ASP Cookies Tutorial In 2024, In this tutorial you can learn Try - Example,What Cookie that?,How to Create a Cookie?,How to retrieve the value of the Cookie?,Cookie with key,Read all of the Cookie,If your browser does not support Cookie how to do?,
cookie used to identify the user.
Welcome cookie
This example demonstrates how to create a Welcome cookie.
cookie used to identify the user. A cookie is a server on the user's computer to stay in a small file. Whenever the same computer via the browser requests a page, this computer will send a cookie. By ASP, you can create and retrieve cookie values.
"Response.Cookies" command is used to create a cookie.
Note: Response.Cookies command must appear before the <html> tag.
In the example below, we will create a cookie named "firstname" and will assign it to "Alex":
Assigned to the cookie attribute is also possible, for example, set the cookie expiration time:
"Request.Cookies" command is used to retrieve a cookie value.
In the following example, we retrieve the value named "firstname" of the cookie, and the value displayed on the page:
Output: Firstname = Alex
If a cookie contains a collection of multiple values, we say that the cookie with keys (Keys).
In the following example, we will create a cookie collection named "user" of. "User" cookie contains the user with key information:
Please read the following code:
Suppose your server will above all cookie passed to a user.
Now, we need to read them all to pass a user cookie. The following example shows you how to do this (note that the code below checks if a cookie by HasKeys property with a key):
Output:
firstname = Alex
user: firstname = John
user: lastname = Smith
user: country = Norway
user: age = 25
If your application needs to deal with do not support the browser cookie, you have to use other methods to pass information in your application between pages. There are two ways:
You can add parameters to the URL:
Then retrieve these values in the "welcome.asp" file, as follows:
You can use the form. When the user clicks the Submit button, the user input form will pass "welcome.asp":
Then retrieve these values in the "welcome.asp" file, as follows: