为什么使用 Response 设置后,Request 中的 Cookie 立即可用?
在页面加载中,如果您执行 Response.Cookies.Add(...,立即在下一行中,您可以通过 Request.Cookies(...
我知道在幕后,cookie 被添加到 Request.Cookies通过.net,但原始请求从未有过该 cookie。
如果我所说的是正确的,那么为什么在下面的请求中不应该使用 cookie 呢? (...为空?
In pageload, if you do Response.Cookies.Add(..., immediately in the next line, you can access that cookie via Request.Cookies(...
I know that under the covers, the cookie is added to Request.Cookies by .net, but the original request never had that cookie.
If what I'm saying is correct, why is it this way? Shouldn't the cookie be available in the following request? Shouldn't the immediate access to Request.Cookies(... be null?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,ASP.NET 确实在幕后执行此操作:
-- MSDN 上的 HttpRequest.Cookies 页面
为什么是这样吗?据猜测,这是因为开发人员希望它是这样工作的。
You're right, ASP.NET does do that behind the scenes:
-- HttpRequest.Cookies page on MSDN
Why is it like that? At a guess, it's because that's how developers expect it to work.