.net 如何统计页面访问量?请指点一下哈类似 detail.aspx?id=**** 把访问量存到数据库中,根据访问量排名。
还有静态新闻页的访问统计 。
还有静态新闻页的访问统计 。
解决方案 »
- repeater放的label之类的控件无法在页面显示
- ASP.NET打印问题
- 这里提示"c:\inetpub\wwwroot\Weblog\Entry.cs(15): 类、结构或接口成员声明中的标记“;”无效,如何修改啊!在线等!!
- 动态生成的dropdownlist,绑定数据后用SelectedIndex=1无法定位到第2条记录!
- 给各位拜年,请教一个网络问题
- PDA开发技术 讨论群,欢迎大家加入
- vs2005 web打包的安装包,安装后,怎么没有文件修改的权限啊
- asp.net 部署问题 急 高分求解决
- 调试过程中出现以下一个问题该如何解决?
- 请问如何接收post传递的客户端的URL地址
- asp.net+sql2005 新人遇到的怪问题(100RMB)
- 在线等!问个小问题!
最好加上对Session的判断,防止同一个用户不断f5刷新造成的增长。
第二句话的意思是,如果此用户己经访问过你的当前页面,则进行一个标记(至于这个如何去标记,方法很多),然后当用户访问此页面的时候,去判断这个标记是否是“己访问”的就成了
其中有创建Session和启动Session的方法
你在创建Session方法中写入Application["count"]+=1
在每个页面中你都可以获得该变量 这个变量就是你网站的访问次数
string id= Request.QueryString["news_id"];
if (id != null)
{
string constr = "server=localhost;database=web;user id=sa;pwd=000";
SqlConnection conn = new SqlConnection(constr); try
{
conn.Open();
//读取阅读次数
string sql = "select viewcount from news where news_id = '" + id + "'";
SqlDataAdapter dpt = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
dpt.Fill(ds, "news"); string num = ds.Tables[0].Rows[0].ToString();
//阅读数加1
string sql1 = "update news set viewcount=viewcount+1 where news_id = '" + id + "'";
SqlCommand comm1 = new SqlCommand(sql1, conn);
comm1.ExecuteNonQuery();
Response.Write("document.write('"+num+"');"); }
catch (Exception er)
{
Response.Write(er.Message);
}
finally
{
conn.Close();
}
}
else
{
Response.Write("document.write('null');");
} }
静态页面的统计。。 上面实现不了 !!静态页面里,如何传送 id 呢?
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;namespace UnitInformation
{
/// <summary>
/// UnitInfo_PageCount の概要の説明です。
/// </summary>
public class UnitInfo_PageCount : System.Web.UI.Page
{
int employeeCD=0;
int pageCD=0;
string IPEmploreerCDPageCD;
DateTime viewTime=new DateTime();
private void Page_Load(object sender, System.EventArgs e)
{
// ページを初期化するユーザー コードをここに挿入します。
// @EmployeeCD decimal(10,0)
// ,@Contents_CD int
// ,@PPM_Sys_CD int
// ,@Operation_CD int
employeeCD=Convert.ToInt32(Request.QueryString["employeeCD"].ToString());
pageCD=Convert.ToInt32(Request.QueryString["pageCD"].ToString());
IPEmploreerCDPageCD=employeeCD.ToString()+"-"+pageCD.ToString();
string PPM_Sys_CD=Request.QueryString["PPM_Sys_CD"];
string Operation_CD=Request.QueryString["Operation_CD"];
if(Session[IPEmploreerCDPageCD]==null)
{
Session[IPEmploreerCDPageCD]=DateTime.Now;
//viewTime=DateTime.Now;
InsertViewInfo(employeeCD,pageCD,PPM_Sys_CD,Operation_CD);
}
else
{
DateTime nowDate=DateTime.Now;
DateTime sessionTime=new DateTime();
sessionTime=Convert.ToDateTime(Session[IPEmploreerCDPageCD].ToString());
TimeSpan ts=nowDate-sessionTime;
if(ts.TotalSeconds>=600)
{
Session[IPEmploreerCDPageCD]=nowDate;
//viewTime=nowDate;
InsertViewInfo(employeeCD,pageCD,PPM_Sys_CD,Operation_CD);
}
}
} private void InsertViewInfo(int EmployeeCD,int pageCD,string PPM_Sys_CD,string Operation_CD)
{
SqlParameter[] param=new SqlParameter[4];
param[0]=new SqlParameter("@EmployeeCD",SqlDbType.Int);
param[1]=new SqlParameter("@Contents_CD",SqlDbType.Int);
param[2]=new SqlParameter("@PPM_Sys_CD",SqlDbType.VarChar);
param[3]=new SqlParameter("@Operation_CD",SqlDbType.VarChar); param[0].Value=EmployeeCD;
param[1].Value=pageCD;
param[2].Value=PPM_Sys_CD;
param[3].Value=Operation_CD;
SqlHelper.ExecuteNonQuery(SqlHelper.DBServer,CommandType.StoredProcedure,"PPM_PROC_UI_pageCount",param); } #region Web フォーム デザイナで生成されたコード
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: この呼び出しは、ASP.NET Web フォーム デザイナで必要です。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}