为什么饼干中要求提供的使用设定的响应后,立即? [英] Why is Cookie available in Request immediately after setting using Response?

查看:132
本文介绍了为什么饼干中要求提供的使用设定的响应后,立即?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在页面加载,如果你这样做Response.Cookies.Add(...,立即在下一行,您可以通过Request.Cookies时(访问饼干...

In pageload, if you do Response.Cookies.Add(..., immediately in the next line, you can access that cookie via Request.Cookies(...

我知道在幕后,该Cookie是由.NET加入到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.

如果我在说什么是正确的,为什么会这样?应该不是饼干可在下面的请求?如果不Request.Cookies时(...的即时访问为空?

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?

推荐答案

您说得对,确实ASP.NET做幕后:

You're right, ASP.NET does do that behind the scenes:

您后,使用添加一个cookie
  <一href=\"http://msdn.microsoft.com/en-us/library/system.web.htt$p$psponse.cookies.aspx\"><$c$c>Htt$p$psponse.Cookies收藏,
  Cookie是在立即可
  的Htt prequest.Cookies 收集,甚至
  如果响应没有被发送到
  客户端

After you add a cookie by using the HttpResponse.Cookies collection, the cookie is immediately available in the HttpRequest.Cookies collection, even if the response has not been sent to the client.

- <一href=\"http://msdn.microsoft.com/en-us/library/system.web.htt$p$pquest.cookies.aspx\">Htt$p$pquest.Cookies在MSDN页面

为什么会这样呢?在猜测,这是因为这是开发人员如何期望它的工作。

Why is it like that? At a guess, it's because that's how developers expect it to work.

这篇关于为什么饼干中要求提供的使用设定的响应后,立即?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆