I need to store an object list in a cookie. I know that I must serialize to store my list in cookie.
I tried to use JsonConvert for serialize and deserialize Object.
This line of code works ok.
Response.Cookies.Add(new HttpCookie("ShoppingCart", JsonConvert.SerializeObject(list)));
but when I try to get the cookie value
var shoppingList = HttpContext.Request.Cookies.Get("ShoppingCart");
I get the following exception:
An exception of type 'System.Web.HttpRequestValidationException' occurred in System.Web.dll but was not handled in user code
Can you please advise what I do wrong here. Thanks! Additional information: A potentially dangerous Request.Cookies value was detected from the client (