简体   繁体   English

在Response.Redirect中传递Cookie

[英]Passing cookies in Response.Redirect

I work with Classic ASP (vbscript), I add cookies to the Response like so: 我使用经典ASP(vbscript),将cookie添加到响应中,如下所示:

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

Then I issue a redirect to "etape2.asp" file: 然后,我发出重定向到“ etape2.asp”文件的命令:

Response.Redirect("etape2.asp");

On the new page ("etape2.asp") that I am redirected to, I try to retrieve a cookie like so: 在我重定向到的新页面(“ etape2.asp”)上,我尝试检索如下cookie:

Request.Cookies("mycookie");

But the cookie is empty!! 但是饼干是空的!

Can anyone think of why the cookies are not being passed? 谁能想到为什么未通过Cookie?

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: 可能值得确保您已预先设置足够长的Cookie到期时间,并设置其适用的路径:

So, in eg etape1.asp, do this... 因此,例如在etape1.asp中,执行此操作...

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... 然后在etape2.asp中,执行此操作...

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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