这是一种不严谨的做法,在浏览量不是很重要的时候可以使用
var oldCookie = Request.Cookies["newsCookie"];
if (oldCookie == null)
{
var newsCookie = new HttpCookie("newsCookie");
newsCookie.Expires = DateTime.Now.Date.AddDays();
newsCookie.Values.Add("" + newsId + "", "'" + newsId + "'");
Response.SetCookie(newsCookie);
model.ClickCount = model.ClickCount + ;
_newsService.Update(model);
}
else
{
if (oldCookie["" + newsId + ""] == null)
{
oldCookie.Values.Add("" + newsId + "", "'" + newsId + "'");
Response.AppendCookie(oldCookie);
model.ClickCount = model.ClickCount + ;
_newsService.Update(model);
}
}