在页面上显示当前在线人数
效果:
1、Global.asax文件:
<%@ application Language="C#" %><%@ Import Namespace="System.xml" %><script runat="server"> void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 //载入配置文档 XmlDocument AppConfig = new XmlDocument(); AppConfig.Load(HttpContext.Current.Server.MapPath("~/AppConfig.xml")); //读取配置信息 XmlNode xnList = AppConfig.GetElementsByTagName("dblist")[0]; XmlElement xeDb1 = (XmlElement)xnList.ChildNodes[0]; XmlElement xeDb2 = (XmlElement)xnList.ChildNodes[1]; Application["db1user"] = xeDb1.GetAttribute("user"); Application["db1source"] = xeDb1.GetAttribute("source"); Application["db2user"] = xeDb2.GetAttribute("user"); Application["db2source"] = xeDb2.GetAttribute("source"); Application["count"] = 0; } void Application_End(object sender, EventArgs e) { //在应用程序关闭时运行的代码 } void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 } void session_Start(object sender, EventArgs e) { //在新会话启动时运行的代码 Application["count"] = Convert.ToInt32(Application["count"])+1; } void Session_End(object sender, EventArgs e) { //在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 // InPRoc 时,才会引发 Session_End 事件。如果会话模式 //设置为 StateServer 或 SQLServer,则不会引发该事件。 Application["count"] = Convert.ToInt32(Application["count"]) - 1; } </script
-----------------------
2、显示页面:
前台:
<span id="Span1" runat="server" class="bottom"> </span>
后台:
Span1.InnerHtml = "当前在线" + Application["count"].ToString() + "人";
新闻热点
疑难解答