온라인 인원 통계

6852 단어 통계적
<%@ Import Namespace="System.Data"%>

void Application_Start(object sender, EventArgs e) 

    {

       //             ,           

        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();

    }

 
    void Session_Start(object sender, EventArgs e) 

    {

        //            ,        Session_Start  , Session_Start          ,    ,
//Application["OnLineusers"]
string sessionid = Session.SessionID; string userIP = Request.UserHostAddress; HttpBrowserCapabilities bc = Request.Browser; string osName = bc.Platform; string Browser=bc.Type; DataTable userTable = (DataTable)Application["OnLineusers"]; if (userTable == null) return; DataRow[] curRow=userTable.Select("SessionId='"+sessionid+"'"); if (curRow.Length == 0) { DataRow newRow = userTable.NewRow(); newRow["SessionID"] = sessionid; newRow[1] = userIP; newRow[2] = Browser; newRow[3] = osName; userTable.Rows.Add(newRow); userTable.AcceptChanges(); Application.Lock(); Application["OnLineusers"] = userTable; Application.UnLock(); } }
   //       Session
  void Session_End(object sender, EventArgs e) { Hashtable onlineuserhash = (Hashtable)Application["OnLineusers"]; onlineuserhash.Remove(Request.UserHostAddress); 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(); }

일반적인 해결 방법: 프로젝트 아래에 txt 파일을 만들어서 온라인 인원수를 저장합니다.SessionStart,Session_end txt 작업

좋은 웹페이지 즐겨찾기