简体   繁体   中英

Passing cookies in Response.Redirect

I work with Classic ASP (vbscript), I add cookies to the Response like so:

Response.Cookies("mycookie") = "var_cookie"

Then I issue a redirect to "etape2.asp" file:

Response.Redirect("etape2.asp");

On the new page ("etape2.asp") that I am redirected to, I try to retrieve a cookie like so:

Request.Cookies("mycookie");

But the cookie is empty!!

Can anyone think of why the cookies are not being passed?

Might be worthwhile making sure you have set an expiry for the cookie far enough in advance, and set the path to which it applies:

So, in eg etape1.asp, do this...

var_cookie_mycookie                   =  "this is the contents of mycookie"

response.cookies("mycookie").expires  =  now + 1
response.cookies("mycookie").path     =  "/"
response.cookies("mycookie")          =  trim(cstr("" & var_cookie_mycookie))

response.redirect                        "etape2.asp"

And in etape2.asp, do this...

var_cookie_mycookie                   =  trim(cstr("" & request.cookies("mycookie")))

response.write                           "<p>Value of 'mycookie' cookie: " &_
                                         server.htmlencode(var_cookie_mycookie) &_
                                         "</p>"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM