I'm trying to create a cookie that stores a list of properties that a user views.
I have created a test, and it works in part. Currently, each time i visit a page, it pulls the property ID from the URL and either creates a new string containing that URL, if if a cookie already exists, it'll append that property ID to it.
@{
var rPropertyId = UrlData[0].AsInt();
if(rPropertyId > 0){
if (Request.Cookies["viewed_properties"] != null){
var value = Request.Cookies["viewed_properties"].Value.ToString();
var value1 = value + "." + rPropertyId;
var newcookievalue = String.Join(".", value1.Split(new Char[] {'.'}).Distinct());
Response.Cookies["viewed_properties"].Value = newcookievalue;
Response.Cookies["viewed_properties"].Expires = DateTime.Now.AddYears(1);
} else {
Response.Cookies["viewed_properties"].Value = rPropertyId.ToString();
Response.Cookies["viewed_properties"].Expires = DateTime.Now.AddYears(1);
}
}
}
@if (Request.Cookies["viewed_properties"] != null){
var mylist = Request.Cookies["viewed_properties"].Value.Split(new Char[] {'.'});
foreach (var i in mylist)
{
<p>@i</p>
}
}
What this process doesn't take into consideration, is that if a user visits the same property more than once, i still want only 1 entry of that ID in the cookie. How would i check this, convert it to an array?