using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;

namespace RBBBS 
{
	/// <summary>
	/// Summary description for Global.
	/// </summary>
	public class Global : System.Web.HttpApplication
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		public Global()
		{
			InitializeComponent();
		}	
		
		protected void Application_Start(Object sender, EventArgs e)
		{
			Application["user_sessions"]=0;
			Application["count"]=0;

		}
 
		protected void Session_Start(Object sender, EventArgs e)
		{
			Application.Lock();
			Application["user_sessions"] = (int)Application["user_sessions"] + 1;
			//判断当前有几个人在线，然后赋值到Application["user_sessions"]变量.
			Application.UnLock();
			//数据库连接
			Session["str_connection"]=System.Configuration.ConfigurationSettings.AppSettings["Connectionstring"];


		}

		protected void Application_BeginRequest(Object sender, EventArgs e)
		{
			Application["StartTime"] = System.DateTime.Now;

		}

		protected void Application_EndRequest(Object sender, EventArgs e)
		{
			System.DateTime startTime = (System.DateTime)Application["StartTime"];
			System.DateTime endTime = System.DateTime.Now;
			System.TimeSpan ts = endTime - startTime;
			Response.Write("<table border=0' bgcolor='#ffffff'  width='100%'><tr><td height='20' align='center' width='100%'><font size=1 color='Silver'>页面执行耗时：" + ts + "秒<font></td></tr></table>");


		}

		protected void Application_AuthenticateRequest(Object sender, EventArgs e)
		{

		}

		protected void Application_Error(Object sender, EventArgs e)
		{

		}

		protected void Session_End(Object sender, EventArgs e)
		{
			Application.Lock();
			Application["user_sessions"] = (int)Application["user_sessions"] - 1;
			//当用户离开站点的时候减1
			Application.UnLock();

		}

		protected void Application_End(Object sender, EventArgs e)
		{

		}
			
		#region Web Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.components = new System.ComponentModel.Container();
		}
		#endregion
	}
}

