HttpCookieCollection.Add VS HttpCookieCollection.Set - 是否Request.Cookies集合被复制到Response.Cookies集合? [英] HttpCookieCollection.Add vs HttpCookieCollection.Set - Does the Request.Cookies collection get copied to the Response.Cookies collection?
问题描述
我只是想清楚这件事。
我知道,如果我设置一个previous要求一个cookie,它会在我的 Request.Cookies时
收集露面。
I know that if I have set a cookie on a previous request, it will show up in my Request.Cookies
collection.
我想更新现有的Cookie。
I want to update my existing Cookie.
从我 Request.Cookies时
收集饼干已经复制到我的 Response.Cookies
收藏?我是否需要添加一个新的cookie使用 Response.Cookies.Add()相同的密钥
,或者我需要使用 Response.Cookies。设置()
?
Are the cookies from my Request.Cookies
collection already copied to my Response.Cookies
collection? Do I need to add a new cookie with the same key using Response.Cookies.Add()
, or do I need to use Response.Cookies.Set()
?
推荐答案
有是有区别的:
-
Response.Cookies.Add()
将允许重复的cookie被设置<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.add.aspx\">http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.add.aspx -
Response.Cookies.Set()
将确保cookie是独一无二的,首先检查,以确保该cookie不存在<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.set.aspx\">http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.set.aspx
Response.Cookies.Add()
will allow duplicate cookies to be set http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.add.aspxResponse.Cookies.Set()
will make sure the cookie is unique by first checking to ensure the cookie doesn't exist http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.set.aspx
复制饼干通常需要额外的处理,以确定哪些是最新的。我不知道的情况下,当你想在同一地点重复的饼干,也许别人可以用一个例子附和
Duplicate cookies typically requires extra handling to determine which is the most recent. I'm not sure of a case when you would want duplicate cookies on the same site, maybe someone else can chime in with an example
编辑:的在您的情况,您要使用设置,因为你正在更新
In your case, you want to use set because you are updating.
这篇关于HttpCookieCollection.Add VS HttpCookieCollection.Set - 是否Request.Cookies集合被复制到Response.Cookies集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!