ASP — Cookies
Set Cookie
<%
Response.Cookies("username") = "John"
Response.Cookies("username").Expires = DateAdd("d", 7, Now)
%>
Get Cookie
<%
Dim username
username = Request.Cookies("username")
If username <> "" Then
Response.Write("Welcome back, " & username)
Else
Response.Write("Welcome, guest")
End If
%>
Cookie Properties
<%
Response.Cookies("user")("name") = "John"
Response.Cookies("user")("email") = "john@example.com"
Response.Cookies("user").Domain = ".example.com"
Response.Cookies("user").Path = "/"
Response.Cookies("user").Secure = True
%>
Delete Cookie
<%
Response.Cookies("username").Expires = DateAdd("d", -1, Now)
%>
Check Cookie
<%
If Request.Cookies("username") <> "" Then
Response.Write("Cookie exists")
Else
Response.Write("No cookie")
End If
%>
Mini Practice
- Set a cookie
- Read a cookie
- Set cookie properties
- Delete a cookie
Up Next
Continue with Sessions — session management.
Related Topics
Frequently Asked Questions about Cookies
What is Cookies in ASP?
Cookies is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Cookies?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Cookies.
Why is Cookies important in ASP?
Cookies is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.