Cookies let a Classic ASP application store a small amount of state in the visitor's browser. ASP writes cookies through Response.Cookies and reads them through Request.Cookies.
A cookie can support preferences or a signed-in experience, but do not store passwords or other sensitive credentials directly in a cookie. For authentication, prefer an opaque token or server-side session design, and apply appropriate transport/security attributes in the deployment environment.
Cookies may also support analytics or preference tracking. Their use should follow applicable privacy requirements and user-consent rules for the deployment.
Browsers scope cookies by domain/path rules, but application code must still avoid placing secrets in client-readable state.
Response.Cookies("Name")=" Ronald "
Response.Cookies("visit")= Now
We can also use Keys to store cookies like this.
Response.Cookies("User")("Name")=" Ronald "
Response.Cookies("User")("visit")= Now
Response.Cookies("Name").Expires = Date +1
Response.Cookies("visit").Expires = Date +1
The above code will set the expire date to next day ( or one day advance ) . We can also increase expire date by another 15 days or to any future date as per the requirement. Same way we can also set expire dates to future fixed dates like this by using date formats.
Response.Cookies("Name").Expires =#February 20, 2010#
Response.Cookies("Name").Expires =DateSerial(2012,1,27)
We can also set the expire date to past like this
Response.Cookies("Name").Expires = Date -1
Setting an expiry date in the past instructs the browser to expire/delete that cookie.
Response.Write(Request.Cookies("Name"))
Response.Write(Request.Cookies("visit"))
If we have used keys then we can read like this
Response.Write(Request.Cookies("User")("Name"))
Response.Write(Request.Cookies("User")("visit"))
Storing small bit of information by cookies helps as server resources are not used and data is kept at client side. This is helpful particularly for sites with large number of visitors. But problem is client may select not to accept cookies. Still cookies are popular in today's browser and it adds value to user experience.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.