We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Cookies expires very soon

aspbank
aspbank asked
on
Medium Priority
1,950 Views
Last Modified: 2012-08-13
Dear All,
I have develped cookies based admin tool this way:
login page wil have this code, after successful log in, cookies wil be written and expired after 1 hr.

strName = objRs("AdminName")
strLogin = objRs("AdminLogin")
intID = objRs("ID")
Response.Cookies("Admin")("name") = strName
Response.Cookies("Admin")("login") = strLogin
Response.Cookies("Admin")("id") = intID
Response.Cookies("Admin").Expires = dateadd("H",1,now)
Response.Redirect("admin.asp")

in admin page first we wil check for saved cookies. code is something like :

Dim adminName, adminId, adminLogin, adminArea

adminName = Request.Cookies("Admin")("name")
adminLogin = Request.Cookies("Admin")("login")
adminId = Request.Cookies("Admin")("id")
adminArea = Request.Cookies("Admin")("area")


IF adminName = "" OR adminLogin = "" OR adminId = "" THEN
Response.Redirect "login.asp"
End IF


now the problem is my cookies are getting expired within 5 min. and i redirecting to login page
how i can fix now ?
Comment
Watch Question

Commented:
There is maybe a possible issue in a difference between datetime on your server and on the clientside.
I think that cookies expires following the client date time, not server.
So, if you create a cookie with expiration now + 1 hour, server date, and that the client is on a time zone with 1 hour more, your cookie will expires as it is created.

Author

Commented:
thanks for your reply,
i removed that line and tried but the same problem

Commented:
Can you try to add a Response.Buffer = True like this:

Response.Buffer = True

...'your code

strName = objRs("AdminName")
strLogin = objRs("AdminLogin")
intID = objRs("ID")
Response.Cookies("Admin")("name") = strName
Response.Cookies("Admin")("login") = strLogin
Response.Cookies("Admin")("id") = intID
Response.Cookies("Admin").Expires = dateadd("H",1,now)
Response.Redirect("admin.asp")
Response.End

Commented:
i'v had an issue like this as well.  and I found that the problem lies with how the cookies are structured.

You have (and I had)  response.cookies("Admin")("name")

i found that using .Expires on the ("Admin") does not work.  What I had to do, was get rid of it.  So I did

response.cookies("Admin_name") = strName
response.cookies("Admin_name").Expires - dateadd("H",1,Now())

and it worked

Author

Commented:
and how about other keys ?
do i need to create 3 cookies seperately ?

response.cookies("Admin_name") = strName
response.cookies("Admin_name").Expires - dateadd("H",1,Now())

response.cookies("Admin_login") = strName
response.cookies("Admin_login").Expires - dateadd("H",1,Now())

response.cookies("Admin_id") = strName
response.cookies("Admin_id").Expires - dateadd("H",1,Now())


this way ?

Author

Commented:
and second thing is i opened temporary intenet folder, there i did not find any file for this cookies. why it is so ?


Commented:
yes, you would need to do the 3 cookies seperatly.

try the cookies folder.  windowsXP and 2000

c:\documents and setting\username\cookies

windows ME and down:(if I remember correctly)

c:\windows\cookies

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
I'm a little confused.  Why the C grade?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.