/// <summary>
/// 更新点击率
/// </summary>
private void updateClick()
{
string nid = Request.QueryString[0].Trim(); //文章ID,看你怎么获取
HttpCookie cookie = Request.Cookies["readNews2"]; //用Cookies防止一天更新多次.
if (cookie != null) //如果cookie的值不为空
{
if (!cookie.Value.Contains(nid)) //如果Cookie里面不包含nid
{
// news2.DAL.nNews.Update_clickCount(nid); //你自己数据库的更新逻辑.
cookie.Value = cookie.Value + nid + "$"; //cookie的值加上nid的值
Request.Cookies.Set(cookie);
cookie.Expires = DateTime.Now.AddDays(1.0);
Response.Cookies.Add(cookie);
}
}
else//cookies的值为空
{
//news2.DAL.nNews.Update_clickCount(nid); //你自己数据库的更新逻辑.
HttpCookie cookie2 = new HttpCookie("readNews2"); //创建Cookies
cookie2.Value = nid + "$"; //cookies的值等于nid
cookie2.Expires = DateTime.Now.AddDays(1.0); //过期时间
Response.Cookies.Add(cookie2); //Cookie加到Cookies里面
}
}
三层,记录浏览次数。
最新推荐文章于 2024-11-01 12:20:35 发布