using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace OnlineUser
{
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)
{
//用Cookie是為了防止同一個用戶重復計數
HttpCookie cookie = Request.Cookies["user"];
if (null == cookie)//確定是否存在用戶輸入的cookie
{
cookie = new HttpCookie("user");//創建一個名稱是user的cookie對象
cookie.Value = "used";//為該cookie賦值,只能是字符串,非字符串需轉換
cookie.Expires = DateTime.Now.AddHou