rt~~谢谢~
解决方案 »
- 泛型问题, 请解答. 谢谢.
- ASP.NET网站邮件功能问题???
- 关于视频播放解决方案
- 请问在asp.net中能否直接调用excel表的预览功能,注意不是生成excel
- 出50分问一个小问题!!!
- 如何保障网站的数据安全?我用的.net+sqlserver2005数据库
- 有关自定义服务器控件的问题
- DataGrid高手进来:如何用DataGrid显示图片列表?
- 在默认的localhost下建立一个 MyWeb/WebForm1.aspx,如何让局域网中的其他机器访问?
- 囊中羞涩,“高分购买”asp.net免费图书下载网站
- Textbox中多个空格如何保留???
- 怎样控制treeview 中NavigateUrl指向不同的页面
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;namespace Demo
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{ Application["count"] = 0;
} protected void Application_End(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
Session.Timeout = 1;
Application.Lock();
Application["count"] = (int)Application["count"] + 1;
Application.UnLock();
}
protected void Session_End(object sender, EventArgs e)
{ Application.Lock();
Application["count"] = (int)Application["count"] - 1;
Application.UnLock();
}
}
} 页面后台代码如下: 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;namespace Demo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = "当前在线人数:" + Application["count"].ToString();
}
}
} 页面前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Demo._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label" Width="128px"></asp:Label></div>
</form>
</body>
</html>
{
Application["user_sessions"] = 0;
}
protected void Session_Start(Object sender, EventArgs e)
{
Application.Lock();
Application["user_sessions"] = (int)Application["user_sessions"] + 1;
Application.Unlock();
}
protected void Session_End(Object sender, EventArgs e)
{
Application.Lock();
Application["user_sessions"] = (int)Application["user_sessions"] - 1;
Application.Unlock();
}
想统计带日期的就在Session_Start事件中加上条件,写人数到一个DataTable中,对应日期和该日期人数,将DataTable保存在Application中,统计的时候取出来就行了。
论坛的也是不准确的,如果用户直接关闭浏览器 那么数据不能及时更新。
所以你要在关闭页面之前添加一个事件用来logout。像中国XX银行登陆后,不管是“退出”还是关闭浏览器/页面,都会弹出对话框“你已经安全退出”。然后断开connect
在Global 中使用全局静态变量就可以了,没不要使用Application
我的意思是在Global 中使用全局静态变量中记录在线人数,不需要把数据保存在Application
中
fuck you! do you know the answer or not? why did you say so much pointless shit?!