一般网站的在线人数的统计是怎么做的? 最简单方法: 每个新 Session 产生的时候加一,每个Session 失效的时候减一。然后这个数据记录到全局变量中,一般也就是 Application 上面的方法。 asp asp.net 都适用。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 see:http://www.kupage.com/webdesign/7/20030223/1458420000007rbyujin.htm 每当有一个浏览器启动时,就会产生一个sessionID,记录该sessionID和最后访问时间,存储到application变量里面,并在global.asa里初始化application和把application变量写到数据库里(如果想简便一点,也可以写到文本文件了,在asp里是用fso) 也可以考虑用一个静态变量,如static string [] arrManNum; to zhenwang:能否说的详细一点? 在global.asax.cs文件中:using System; using System.Collections; using System.ComponentModel; using System.Web; using System.Web.SessionState; using System.IO ; namespace counter2 { public class Global : System.Web.HttpApplication { protected void Application_Start(Object sender, EventArgs e) { uint count=0; StreamReader srd; //取得文件的实际路径 string file_path=Server.MapPath ("counter.txt"); //打开文件进行读取 srd=File.OpenText (file_path); while(srd.Peek ()!=-1) { string str=srd.ReadLine (); count=UInt32.Parse (str); } object obj=count; Application["counter"]=obj; srd.Close (); } protected void Session_Start(Object sender, EventArgs e) { Application.Lock (); //数值累加,注意这里使用了装箱(boxing) uint jishu=0; jishu=(uint)Application["counter"]; jishu=jishu+1; object obj=jishu; Application["counter"]=obj; //将数据记录写入文件 string file_path=Server.MapPath ("counter.txt"); StreamWriter fs=new StreamWriter(file_path,false); fs.WriteLine (jishu); fs.Close (); Application.UnLock (); } protected void Application_BeginRequest(Object sender, EventArgs e) { } protected void Application_EndRequest(Object sender, EventArgs e) { } protected void Session_End(Object sender, EventArgs e) { } protected void Application_End(Object sender, EventArgs e) { //装箱 uint js=0; js=(uint)Application["counter"]; //object obj=js; //Application["counter"]=js; //将数据记录写入文件 string file_path=Server.MapPath ("counter.txt"); StreamWriter fs=new StreamWriter(file_path,false); fs.WriteLine(js); fs.Close (); } } } //************************************************在要显示计数器的页面中加入<%=Application["counter"]%> 寻找提高图片清晰度的方法 进着有份 只求一答案 请教一个下载的问题。 最近面试 遇到这样一个题目。 在一个页面中,如何获取用户是否刷新过该页 在detailsview使用dropdownlist更新不成功 简单问题 急 大家请帮忙,在线等~~! 高分求asp.net(vb)操作数据库(sqlserver2000)的例子或代码 关闭弹窗重新绑定listview问题 点击关闭关闭不了高亮层 怎样获取用户上传图片的长度和高度,并把该数据存到数据库中啊???? ASP引用FileAccess组件的问题 FSO
能否说的详细一点?
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.IO ;
namespace counter2
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(Object sender, EventArgs e)
{
uint count=0;
StreamReader srd;
//取得文件的实际路径
string file_path=Server.MapPath ("counter.txt");
//打开文件进行读取
srd=File.OpenText (file_path);
while(srd.Peek ()!=-1)
{
string str=srd.ReadLine ();
count=UInt32.Parse (str);
}
object obj=count;
Application["counter"]=obj;
srd.Close ();
} protected void Session_Start(Object sender, EventArgs e)
{
Application.Lock ();
//数值累加,注意这里使用了装箱(boxing)
uint jishu=0;
jishu=(uint)Application["counter"];
jishu=jishu+1;
object obj=jishu;
Application["counter"]=obj;
//将数据记录写入文件
string file_path=Server.MapPath ("counter.txt");
StreamWriter fs=new StreamWriter(file_path,false);
fs.WriteLine (jishu);
fs.Close ();
Application.UnLock ();
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
}
protected void Session_End(Object sender, EventArgs e)
{
}
protected void Application_End(Object sender, EventArgs e)
{
//装箱
uint js=0;
js=(uint)Application["counter"];
//object obj=js;
//Application["counter"]=js;
//将数据记录写入文件
string file_path=Server.MapPath ("counter.txt");
StreamWriter fs=new StreamWriter(file_path,false);
fs.WriteLine(js);
fs.Close ();
}
}
}
//************************************************
在要显示计数器的页面中加入<%=Application["counter"]%>