How to get the number of online users in asp.net

Posted by Prabu_Spark under News and Community on 10/30/2012 | Points: 10 | Views : 4834 | Status : [Member] | Replies : 3
Hi sir,
how to get the number of online users in asp.net . In your website it is displaying number of online users. I need the solution for this problem.
I am fresher in dotnet domain. Please help me.

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Ranjeet_8 on: 10/30/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Add this code on your Global.asax Page

public void Session_Start(object sender, EventArgs e)
{
// Fires when the session is started
Application["UserCount"] = Convert.ToInt32(Application["UserCount"].ToString()) + 1;
}
public void Session_End(object sender, EventArgs e)
{
// Fires when the session ends
Application["UserCount"] = Convert.ToInt32(Application["UserCount"].ToString()) - 1;
}

Add this code on your Master Page

private void Page_Load(System.Object sender, System.EventArgs e)
{
//Put user code to initialize the page here
this.lblUserCount.Text = "Users online " + Application["UserCount"].ToString();
}


Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 10/30/2012 [Member] Starter | Points: 25

Up
0
Down
Hi..
For more info refer the below links......
http://www.dotnetcode.in/2011/06/how-to-find-number-of-online.html

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sourabh07 on: 10/30/2012 [Member] Starter | Points: 25

Up
0
Down
hi to all,

the code published by ranjeet sir....is up to the level

For more effectiveness of the code.....please make these edition to the events fired in Global.asax Page.

 Application.Lock();

Application["UserCount"] = Convert.ToInt32(Application["UserCount"].ToString()) + 1;
Application.UnLock();


Sourabh07

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response