ddc
联网
平面设计 画册 VI欣赏 包装 CG-插画 搜索 个人网页 Alexa排名 CSS 建站资源 下载专区 JS特效 品牌服装 服装院校 专题欣赏 SEO 图标欣赏 专题
网站建设 域名注册 网站建设 虚拟主机 广州网站设计 域名注册 广州网站建设 上海网站建设 虚拟主机 广州网页设计 虚拟主机 域名注册 acg王国 ACG玩家 品牌设计 上海网站建设
求创科技
网站建设
中国互联
素材出售
中国设计秀
中资源
当前位置:网络学院首页 >> 编程开发 >> .net >> asp.net中对静态页面访问统计代码

asp.net中对静态页面访问统计代码 (1)

来源:中国设计秀    作者:    点击:705     加入收藏    发表评论
0
顶一下
 

    访问量的统计方法据说有好几种,我也没都搞明白,有利用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 + "")");//很关键
            }
        }

[1] [2]
2007-07-25 09:12:00    出处:
Google