German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


Show online Users/Members in ASP .NET

Written by omerkamal on Jul 24, 2007
How to display online Users or members using ASP .NET 2.0

Explanation:

add a gridview to your Page. Customised the  . So it tells no online user when no one is online.


          
           

No online User


          

Now in the code behind create a DataView so later you can sort it according to LastLoginDate of the User.


 

public DataView GetAllUsersDataTable()
    {
        MembershipUserCollection mc = Membership.GetAllUsers();

        DataTable dt = new DataTable("LastUsers");
        dt.Columns.Add("UserName", typeof(string));
        dt.Columns.Add("Ldate", typeof(DateTime));
        foreach (MembershipUser st in mc)
        {
            if (st.IsOnline)
                dt.Rows.Add(new Object[] { st.UserName, st.LastLoginDate});
        }

        dt.AcceptChanges();
        DataView dv = new DataView(dt);
        return dv;
    }


On the Page Load event of the Page bind your Gridview to the created DataView.


 

DataView tView = GetAllUsersDataTable();
tView.Sort = "Ldate DESC";
GridView1.DataSource = tView;
GridView1.DataBind();


Download the Code: CheckOnlineUsers.zip

Visitors/Readers Comments
(for questions please use The Forum)



def

ang galing

29/07/2007 21:12:10 UTC

ranganath
this is very useful programme to follow the applications

01/08/2007 01:36:48 UTC

Umair Hafeez
This was a good help for me. Thanx

19/11/2007 10:27:21 UTC

planet06
Merhaba ömer bey. Bu konuda çok araştırma yaptım ama bulamadım. Sizinkini bulunca ilk önce sevindim ancak kodlarınız çalştıramadım. Download linkinde ise sadece bir aspx dosyası var kod kısmı yok.  Benim yapmak istediğim siteye bağlı online kullanıcıları görebilmek? Bunu yapacak çalışan bir kodu nerden bulabilirim

16/04/2008 06:39:35 UTC

Richard
This only works if you have 20 users on your site.  What if you have 20,000

04/06/2008 21:33:02 UTC




Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)