我在网站首页里写入js<script runat="server" type="text/javascript">
void Application_Start(object sender,EventArgs e)
{
Application["counter"]=0;
} void Session_Start(object sender,EventArgs e)
{
Application.Lock();
if (Application["counter"] == null)
{
Application["counter"] = 0;
}
Application["counter"]=(int)Application["counter"]+1;
Application.UnLock();
} void Session_End(object sender,EventArgs e)
{
Application.Lock();
Application["counter"]=(int)Application["counter"]-1; Application.UnLock();
}
</script>
首页尾部输出
<div>
浏览人数: <% Response.Write(Application["counter"]);%>
</div>
但在浏览页面时无法显示人数,是哪里错了呢?
void Application_Start(object sender,EventArgs e)
{
Application["counter"]=0;
} void Session_Start(object sender,EventArgs e)
{
Application.Lock();
if (Application["counter"] == null)
{
Application["counter"] = 0;
}
Application["counter"]=(int)Application["counter"]+1;
Application.UnLock();
} void Session_End(object sender,EventArgs e)
{
Application.Lock();
Application["counter"]=(int)Application["counter"]-1; Application.UnLock();
}
</script>
首页尾部输出
<div>
浏览人数: <% Response.Write(Application["counter"]);%>
</div>
但在浏览页面时无法显示人数,是哪里错了呢?
解决方案 »
- asp.net 行转列 动态列 怎么绑定GRIDVIEW
- 换了个电脑,换了个vs 打开resx就一样了 有图~
- 服务器端的父子窗口传值问题
- 对datagrid的操作,马上结帐
- .net 2005 中自带了控件reportviewer,请问如何在这个.net已有的reportviewer下调用reporting serivce2005服务器端的现有报表!
- 请大家一个问题:我现在在做报表了,由于报表比较复杂,现在是一个查询产生一个报表, 大家是如何做报表的,有什么经验请指点,谢谢
- 很急的问题,应该不难
- mysql汉字存储设置问题
- 简单问题
- 一个将B网页的值送回A网页的问题。
- 悄悄地问一下!!
- 有人知道C#调用迅雷组件,提交下载任务时,不弹出对话框吗?
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Xml.Linq;namespace CountPerson
{
public class Global : System.Web.HttpApplication
{ protected void Application_Start(object sender, EventArgs e)
{
#region OnlineUsers
try
{
DataTable userTable = new DataTable();
userTable.Columns.Add("SessionID");
userTable.Columns.Add("UserIP");
userTable.Columns.Add("Browser");
userTable.Columns.Add("OSName"); userTable.AcceptChanges();
Application.Lock();
Application["OnlineUsers"] = userTable;
Application.UnLock();
}
catch
{ }
#endregion
} protected void Session_Start(object sender, EventArgs e)
{
try
{
string sessionid = Session.SessionID;
string userIP = Request.UserHostAddress;
HttpBrowserCapabilities bc = Request.Browser;
string osName = "win2000";
//判断操作系统
switch (bc.Platform)
{
case "WinNT 5.1":
case "WinXP":
osName = "Windows XP";
break;
case "WinNT 5.0":
osName = "Win2000";
break;
case "WinNT":
osName = "Win2003";
break;
default:
osName = bc.Platform;
break;
}
string browser = bc.Type;
DataTable userTable = (DataTable)Application["OnlineUsers"];
if (userTable == null)
return;
DataRow[] curRow = userTable.Select("SessionID='" + sessionid + "'");
if (curRow.Length == 0)
{
DataRow row = userTable.NewRow();
row["SessionID"] = sessionid;
row["UserIP"] = userIP;
row["Browser"] = browser;
row["OSName"] = osName; userTable.Rows.Add(row);
userTable.AcceptChanges(); Application.Lock();
Application["OnlineUsers"] = userTable;
Application.UnLock();
}
}
catch
{
}
} protected void Application_BeginRequest(object sender, EventArgs e)
{ } protected void Application_AuthenticateRequest(object sender, EventArgs e)
{ } protected void Application_Error(object sender, EventArgs e)
{ } protected void Session_End(object sender, EventArgs e)
{
Hashtable onlineUserHashtable = (Hashtable)Application["OnlineUsers"];
onlineUserHashtable.Remove(Request.UserHostAddress);
try
{
string sessionid = Session.SessionID;
DataTable userTable = (DataTable)Application["OnlineUsers"];
if (userTable == null)
return;
foreach (DataRow row in userTable.Select("SessionID='" + sessionid + "'"))
{
userTable.Rows.Remove(row);
}
userTable.AcceptChanges();
Application.Lock();
Application["OnlineUsers"]= userTable;
Application.UnLock();
}
catch
{
}
} protected void Application_End(object sender, EventArgs e)
{ }
}
}在页面中使用GridView绑定用户列表:
protected void Page_Load(object sender, EventArgs e)
{
DataTable userTable = null;
try
{
userTable = (DataTable)Application["OnlineUsers"];
}
catch
{
Response.Write("获得内存在线数据失败");
}
if (userTable != null)
{
GridView1.DataSource = userTable;
GridView1.DataBind();
}
}