Request.Cookies时和Response.Cookies的区别 [英] Difference between Request.Cookies and Response.Cookies

查看:398
本文介绍了Request.Cookies时和Response.Cookies的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这两个多次在我的code和真的不知道有什么区别,如果一个Cookie设置不应该是完全一致的请求和响应的一样吗?并要求要到最先进的日期,或者回应?

I use both of these many times in my code and don't really know what the difference is , if a cookie is set shouldn't it be exactly the same in request and response? and is request going to the the most up to date , or response?

编辑:

好吧,我得到一个请求和响应之间的差异,但如果我键入

ok , I get the difference between a request and a response, but if I type

string a = HttpContext.Current.Request.Cookie["a"].Value;

它是大部分时间的相同

it is most of the time the same as

string a = HttpContext.Current.Response.Cookie["a"].Value;

但我想知道什么是使用二者的区别。

but I am wondering what is the difference between using the two.

推荐答案

由于大家都说 Request.Cookies时应该是饼干从客户端(浏览器)和未来的 Response.Cookies 是cookies,将发送回客户端(浏览器)。

As everyone says Request.Cookies are supposed to be cookies coming from client (browser) and Response.Cookies are cookies that will be send back to client (browser).

有一个<打击>魔法有据可查* code,从响应饼干请求副本值。饼干当你添加饼干响应。作为结果,它看起来像你必须在这两个要求响应相同的饼干。请注意,这些复制的饼干没有来自客户端...所以要小心作出错误的决定。

There is a black magic well documented* code that copies values from Response cookies to Request.Cookies when you add cookies to Response. As result it looks like you have same cookies in both Request and Response. Note that these copied cookies did not come from the client... so beware of making wrong decisions.

下面是一个关于code链接到讨论: http://forums.asp.net/t/ 1279490.aspx 。特别是,在下面的方式添加的饼干将在 Request.Cookies时收集显示:

Here is a link to discussion about the code: http://forums.asp.net/t/1279490.aspx. In particular, cookies added in the following way will show up in the Request.Cookies collection:

Response.Cookies.Add(HttpCookie("MyCookie", "MyValue"))


* cookie的行为与 Response.Cookies 使用拷贝记录在<一个href="http://msdn.microsoft.com/en-us/library/system.web.htt$p$psponse.cookies.aspx"><$c$c>Htt$p$psponse.Cookies文章:


*The behavior of cookies getting copied from Response.Cookies is documented in the HttpResponse.Cookies article:

在使用的Htt presponse.Cookies 集合添加一个cookie,该cookie是立即在的Htt $ P $可用pquest.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.

这篇关于Request.Cookies时和Response.Cookies的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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