Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to update the browser cookie before page response ended. basically, i want to update cookie continuously and access this cookie on some other methods but it did not update until response.end() method is executed. so give me some alternate solution.


Thanks.

What I have tried:

For Create Cookie

var DBCookie = new HttpCookie("CookieName")
DBCookie["ID1"]="1";
DBCookie["ID2"]="2";
DBCookie["ID3"]="3";
DBCookie.Expires = DateTime.Now.AddMinutes(60);
HttpContext.Current.Response.Cookies.Add(DBCookie);



For Update Cookie

var DBCookieOld = HttpContext.Current.Request.Cookies["CookieName"];
DBCookieOld["ID1"]="4";
DBCookieOld["ID2"]="5";
DBCookieOld["ID3"]="6"
DBCookieOld.Expires = DateTime.Now.AddMinutes(60);
HttpContext.Current.Response.Cookies.Add(DBCookieOld);
Posted
Updated 6-Oct-17 4:49am
v3
Comments
F-ES Sitecore 6-Oct-17 7:39am    
Update where? On the client or the server-side cookie collections? Cookie updates are sent to the client with the finished page which is why they only update on the client when the page finishes.
Dev_TechnoLabs 6-Oct-17 7:50am    
I have updated this cookie on the server side.I know cookie updates are sent with page response and it will affect the browser cookie when the response ended. but in my case, i want to update the cookie collection before page finish.

1 solution

You cannot update the cookies before the page finishes because they won't be sent back to the client until the page finishes. What you are asking is not making any sense.

Perhaps you want to use a jqery ajax call instead of a page postback.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900