ASP. NET C # implements real-time user online

Source: Internet
Author: User

 Public Static classuseronline{/// <summary>    ///get or set the online list/// </summary>     Public StaticHashtable onlineuserlist {Get        {            if(httpcontext.current.application["onlineuserlist"] ==NULL) {Hashtable onlineuserlist=NewHashtable (); httpcontext.current.application["onlineuserlist"] =onlineuserlist; }            return(Hashtable) httpcontext.current.application["onlineuserlist"]; }        Set{httpcontext.current.application["onlineuserlist"] =value; }    }    /// <summary>    ///Add online Members/// </summary>     Public Static BOOLOnlineuserlist_add (stringKeystringvalue) {        Try        {            if(Onlineuserlist.contains (key)) Onlineuserlist[key]=value; ElseOnlineuserlist.add (key, value); return true; }        Catch        {            return false; }    }    /// <summary>    ///Add online Members/// </summary>     Public Static BOOLOnlineuserlist_add (stringkey) {        stringValue =DateTime.Now.ToString (); returnOnlineuserlist_add (key, value); }    /// <summary>    ///Delete users offline/// </summary>     Public Static BOOLOnlineuserlist_delete (stringkey) {        BOOLRe =false; if(Onlineuserlist.contains (key)) {Hashtable userlist=onlineuserlist;            Userlist.remove (key); Onlineuserlist=userlist; return true; }        returnre; }    /// <summary>    ///determine if the user is online/// </summary>     Public Static BOOLuserIsOnline (stringadminname)        {onlineclearuserouttimeinonlinelist (); returnOnlineuserlist.contains (adminname)?true:false; }    /// <summary>    ///Delete Timeout online users/// </summary>     Public Static voidonlineclearuserouttimeinonlinelist () {intOnlinetimeout = -; Hashtable List=NewHashtable (); Hashtable temlist=NewHashtable (); List=onlineuserlist; Temlist=NewHashtable (list); foreach(DictionaryEntry deinchtemlist) {            //Delete TimeoutDateTime Onlinetime =Convert.todatetime (DE.            Value); TimeSpan TimeSpan= DateTime.Now-Onlinetime; //Delete online time and current time interval greater than timeout minutes (note: The user illegally closes the browser)            if(Timespan.totalminutes >= (Double) {onlinetimeout) {list. Remove (DE.            Key); }} onlineuserlist=list; }}

ASP. NET C # implements real-time user online

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.