静态页面浏览数统计 for asp.net

本文介绍了一个简单的.NET网页应用程序,用于实现网站上文章阅读次数的自动计数功能。通过调用count.aspx页面并传递文章ID参数,可以记录每篇文章被访问的次数,并在页面上显示出来。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1在静态页面加入 <script src="../user/count.aspx?id=6"></script>  
<DIV id=ny_detailmain_tit02><FONT color=#00000>作者:</FONT>杨彩 <FONT color=#00000>出处:</FONT> <FONT color=#00000>时间:</FONT>  <FONT color=#00000>阅读次数:<script src="../user/count.aspx?id=6"></script></FONT>
 
</DIV>

2.建立.net页面 count.aspx   首先把count.aspx页面里面的代码除第一行 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="count.aspx.cs" Inherits="user_count" %> 外,其它全部都删掉

count.aspx

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

 

count.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;

public partial class user_count : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        
string id = Request.QueryString["id"];
        
if (id != null)
        {
            DB manager 
= new DB();
            
string num = manager.oneNumber("select aReadTime from article where aID=" + id);  //读阅读数
            manager.insertdata("update article set aReadTime=aReadTime+1 where aID=" + id);   //阅读数加1
            manager.close();
            Response.Write(
"document.write('" + num + "');");
        }
        
else
        {
            Response.Write(
"document.write('null');");
        }

        
    }
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值