HttpCookieCollection.Add vs HttpCookieCollection.Set - Does the Request.Cookies collection get copied to the Response.Cookies collection?

后端 未结 1 1577
悲&欢浪女
悲&欢浪女 2020-12-03 20:59

I just want to clear this up.

I know that if I have set a cookie on a previous request, it will show up in my Request.Cookies collection.

I wa

相关标签:
1条回答
  • 2020-12-03 21:31

    There is a difference:

    • Response.Cookies.Add() will allow duplicate cookies to be set http://msdn.microsoft.com/en-us/library/system.web.httpcookiecollection.add.aspx
    • Response.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

    Edit: In your case, you want to use set because you are updating.

    0 讨论(0)
提交回复
热议问题