p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Verifying cookie persistance/overwriting


Message #1 by "P Baldyga" <pjb1997@y...> on Mon, 25 Jun 2001 12:14:38
I'm having trouble testing cookie persistance.  I'm new to ASP programming 
and would really appreciate if someone could help me out.  I have 
set a cookie to expire in 32 days.  I want the user to get a fresh 32 day 
cookie each time they hit the site.  So if they hit the site within the 32 
day threshold, the cookie is automatically refreshed.  If they don't 
revisit the site within the 32 day threshold, they are redirected to a 
login page. To test, I set a system clock forward.  My test results have 
actually varied.  I'm checking in IE 5.5 and Netscape 4.7.  I close all 
browsers and have been careful and methodical (seemingly) in my testing 
procedures, but the refreshing/rewrite results have varied.  I can't tell 
if it's environmental (or driver error on my part).  Is there any 
preferred method for  a:) writing the cookie to expire and refresh every 
time the site is hit and b:) accurately checking the cookie 
expiration/overwriting?  I'm especially interested in testing, as 
explicitly as possible (setting date forward?), because that's how my QA 
department wants to test this.

To test, I use two pages, default.asp and cookie.asp.

Here is the code for cookie.asp:

<%	Option Explicit
	
	Response.Cookies("robot")("item1") = "item1content"
	Response.Cookies("robot")("item2") = "item2content"	
	Response.Cookies("robot").Expires = Date + 32

	%>


Here is the code for default.asp:

<%	Option Explicit
	Response.Buffer = True
	%>
<% 
If Request.Cookies("robot").HasKeys Then

	Response.Cookies("robot").Expires = Date + 32
	Response.Redirect("refresh.htm")
	
Else Response.Redirect("nocookie.htm")

End If
	%>

Thanks for helping,

Phil

  Return to Index