asp.net统计当前在线人员 我想判断当前在线人员,想了一个很笨的方法,就是数据库建一个表记录每个用户登陆和退出的时间,在进行判断,,可是退出时间也不好记录啊,如果不是正常的关闭,那退出时间就不知道了?在网上看了一些,应该有一些简便的方法吧,监测当前在线用户。比如写到global.asax中?,可是试了很多都没有成功,大家可不可以给个详细的例子啊,谢谢了,可发到 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void application_start(object sender, eventargs e) { //在应用程序启动时运行的代码 application["count"] = 0; system.io.filestream fs = system.io.file.open(server.mappath("count.txt"), system.io.filemode.openorcreate); system.io.streamreader sr = new system.io.streamreader(fs); application["allusers"] = convert.toint32(sr.readline()); sr.close(); fs.close(); } void application_end(object sender, eventargs e) { //在应用程序关闭时运行的代码 } void application_error(object sender, eventargs e) { //在出现未处理的错误时运行的代码 } void session_start(object sender, eventargs e) { //在新会话启动时运行的代码 application.lock(); application["count"] = convert.toint32(application["count"]) + 1; application["allusers"] = convert.toint32(application["allusers"]) + 1; system.io.filestream fs = new system.io.filestream("count.txt", system.io.filemode.openorcreate, system.io.fileaccess.readwrite); system.io.streamwriter sw = new system.io.streamwriter(fs); sw.writeline(application["allusers"]); sw.close(); fs.close(); application.unlock(); } void session_end(object sender, eventargs e) { //在会话结束时运行的代码。 // 注意: 只有在 web.config 文件中的sessionstate 模式设置为inproc时,www.3ppt.com才会引发 session_end 事件。如果会话模式设置为 stateserver 或 sqlserver,则不会引发该事件。 application.lock(); application["count"] = convert.toint32(application["count"]) - 1; application.unlock(); } 页面只要读出application的内容就行啦: response.write(application["count"]+"当前人数"+" 总人数:"+application["allusers"]); void application_start(object sender, eventargs e) { //在应用程序启动时运行的代码 application["count"] = 0; system.io.filestream fs = system.io.file.open(server.mappath("count.txt"), system.io.filemode.openorcreate); system.io.streamreader sr = new system.io.streamreader(fs); application["allusers"] = convert.toint32(sr.readline()); sr.close(); fs.close(); } void application_end(object sender, eventargs e) { //在应用程序关闭时运行的代码 } void application_error(object sender, eventargs e) { //在出现未处理的错误时运行的代码 } void session_start(object sender, eventargs e) { //在新会话启动时运行的代码 application.lock(); application["count"] = convert.toint32(application["count"]) + 1; application["allusers"] = convert.toint32(application["allusers"]) + 1; system.io.filestream fs = new system.io.filestream("count.txt", system.io.filemode.openorcreate, system.io.fileaccess.readwrite); system.io.streamwriter sw = new system.io.streamwriter(fs); sw.writeline(application["allusers"]); sw.close(); fs.close(); application.unlock(); } void session_end(object sender, eventargs e) { //在会话结束时运行的代码。 // 注意: 只有在 web.config 文件中的sessionstate 模式设置为inproc时,www.3ppt.com才会引发 session_end 事件。如果会话模式设置为 stateserver 或 sqlserver,则不会引发该事件。 application.lock(); application["count"] = convert.toint32(application["count"]) - 1; application.unlock(); } 页面只要读出application的内容就行啦: response.write(application["count"]+"当前人数"+" 总人数:"+application["allusers"]); 楼上的代码应该写在 Global.asa 文件里的吧 这个东西统计不了那么准的,用session可能好点吧,在session_start的时候记录登录时间,在session_end的时候记录退出时间,退出时间偏差在设定的session过期时间内。 会话结束后,asp.net的会自动处理吧。比如session,应该有个会话结束的事件把在那里面写 5楼说的不够详细吗,membership里也是这样做的。 session 用数据库存。或在客户端定时发送在线数据。(服务器负载较大)不知道云技术能不能做。(大牛玩的) 升猩!暨问个技术问题可散技术分! 正则替换的问题 带分隔符的string 类型数据 如何分割插入listbox? CuteEditor5.0图片上传问题(asp.net) *******麻烦大家给我看下这个错误是配置错误 .net复杂数据报表显示问题,高手给个思路! 急啊!!如何改变图像的大小啊 谁有 检测浏览器关闭事件 的代码? jQuery+easyui树型导航问题 从数据库读取图片路径,前台滚动。 100分大出血 ASP.net 显示页面不全问题 ajax问题
void application_start(object sender, eventargs e)
{
//在应用程序启动时运行的代码
application["count"] = 0;
system.io.filestream fs = system.io.file.open(server.mappath("count.txt"), system.io.filemode.openorcreate);
system.io.streamreader sr = new system.io.streamreader(fs);
application["allusers"] = convert.toint32(sr.readline());
sr.close();
fs.close();
}
void application_end(object sender, eventargs e)
{
//在应用程序关闭时运行的代码
}
void application_error(object sender, eventargs e)
{
//在出现未处理的错误时运行的代码
}
void session_start(object sender, eventargs e)
{
//在新会话启动时运行的代码
application.lock();
application["count"] = convert.toint32(application["count"]) + 1;
application["allusers"] = convert.toint32(application["allusers"]) + 1;
system.io.filestream fs = new system.io.filestream("count.txt", system.io.filemode.openorcreate, system.io.fileaccess.readwrite);
system.io.streamwriter sw = new system.io.streamwriter(fs);
sw.writeline(application["allusers"]);
sw.close();
fs.close();
application.unlock();
}
void session_end(object sender, eventargs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 web.config 文件中的sessionstate 模式设置为inproc时,www.3ppt.com才会引发 session_end 事件。如果会话模式设置为 stateserver 或 sqlserver,则不会引发该事件。
application.lock();
application["count"] = convert.toint32(application["count"]) - 1;
application.unlock();
}
页面只要读出application的内容就行啦:
response.write(application["count"]+"当前人数"+"
总人数:"+application["allusers"]);
void application_start(object sender, eventargs e)
{
//在应用程序启动时运行的代码
application["count"] = 0;
system.io.filestream fs = system.io.file.open(server.mappath("count.txt"), system.io.filemode.openorcreate);
system.io.streamreader sr = new system.io.streamreader(fs);
application["allusers"] = convert.toint32(sr.readline());
sr.close();
fs.close();
}
void application_end(object sender, eventargs e)
{
//在应用程序关闭时运行的代码
}
void application_error(object sender, eventargs e)
{
//在出现未处理的错误时运行的代码
}
void session_start(object sender, eventargs e)
{
//在新会话启动时运行的代码
application.lock();
application["count"] = convert.toint32(application["count"]) + 1;
application["allusers"] = convert.toint32(application["allusers"]) + 1;
system.io.filestream fs = new system.io.filestream("count.txt", system.io.filemode.openorcreate, system.io.fileaccess.readwrite);
system.io.streamwriter sw = new system.io.streamwriter(fs);
sw.writeline(application["allusers"]);
sw.close();
fs.close();
application.unlock();
}
void session_end(object sender, eventargs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 web.config 文件中的sessionstate 模式设置为inproc时,www.3ppt.com才会引发 session_end 事件。如果会话模式设置为 stateserver 或 sqlserver,则不会引发该事件。
application.lock();
application["count"] = convert.toint32(application["count"]) - 1;
application.unlock();
}
页面只要读出application的内容就行啦:
response.write(application["count"]+"当前人数"+"
总人数:"+application["allusers"]);
5楼说的不够详细吗,membership里也是这样做的。