httpcookiecollection

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

霸气de小男生 提交于 2019-12-17 13:45:23
问题 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 want to update my existing Cookie. 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() ? 回答1: There is a difference: Response.Cookies.Add() will allow duplicate cookies to be set http:/

What is the best practice for updating a cookie that was set on a previous request in ASP.NET?

痴心易碎 提交于 2019-12-11 07:08:41
问题 Here is the scenario. A cookie with the key "MyCookie" has been set on a previous request. I can access it via HttpContext.Request.Cookies.Get("MyCookie") . I want to perform an update such as adding another value to the Cookie Values collection, but I'm not 100% sure I am doing it right. Am I doing this correctly in the following example? public static void UpdateCookie(HttpContext context, string cookieName, Action<HttpCookie> updateCookie){ var cookie = context.Request.Cookies.Get

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

蹲街弑〆低调 提交于 2019-11-27 15:27:14
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 want to update my existing Cookie. 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() ? 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