asp.net(c#)对静态页面访问量的统计

访问量的统计方法据说有好几种,我也没都搞明白,有利用ajax的,写js脚本的,我用的这个也不知道是什么方法。

在生成的静态页面中有这样一句代码:<script src="http://localhost/.NET/NewsFiles/ClickCount.aspx?NewsId=46"></script>,其中的NewsId是生成静态页面的时候替换的。

其中ClickCount.aspx页面除了page指令都删除,如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClickCount.aspx.cs" Inherits="ClickCount.NewsFiles_ClickCount" %>

ClickCount.aspx.cs的代码如下:

 
using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;
using  Mysqlserver; // 数据库操作类
namespace  ClickCount
{
    
public partial class NewsFiles_ClickCount : System.Web.UI.Page
    
{
        
protected void Page_Load(object sender, EventArgs e)
        
{
            
string strNewsId = Request.QueryString["NewsId"].ToString();//接收传过来的新闻id
            SqlServerDataBase db = new SqlServerDataBase();//建立数据对象
            db.Update("update inNews set ViewCount=ViewCount+1 where NewsId='" + strNewsId + "'"null);//更新加1
            DataSet ds = db.Select("select ViewCount from inNews where NewsId='" + strNewsId + "'"null);//选择更新后的浏览值
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                Response.Write(
"0");
            
else
            
{
                
string count = ds.Tables[0].Rows[0]["ViewCount"].ToString();
                Response.Write(
"document.write("" + count + "")");//很关键
            }

        }


    }

}

 

特别要注意要把ClickCount.aspx的其余代码删除,要不会报错。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值