//给你一段我写的统计文章的C#代码
//文章表中需要有点击数这个字段,或者有一个统计文章点击的表.
//文章页面被加载的时候执行updateClick()方法.
///
/// 更新点击率
///
private void updateClick()
{
string nid = Request.QueryString[0].Trim();//文章ID,看你怎么获取
HttpCookie cookie = Request.Cookies["readNews2"];//用Cookies防止一天更新多次.
if (cookie != null)
{
if (!cookie.Value.Contains(nid))
{
news2.DAL.nNews.Update_clickCount(nid);//你自己数据库的更新逻辑.
cookie.Value = cookie.Value + nid + "$";
Request.Cookies.Set(cookie);
cookie.Expires = DateTime.Now.AddDays(1.0);
Response.Cookies.Add(cookie);
}
}
else
{
news2.DAL.nNews.Update_clickCount(nid);//你自己数据库的更新逻辑.
HttpCookie cookie2 = new HttpCookie("readNews2");
cookie2.Value = nid + "$";
cookie2.Expires = DateTime.Now.AddDays(1.0);
Response.Cookies.Add(cookie2);
}
}