dispaly number of online user on webpage

Ankitsrist
Posted by Ankitsrist under ASP.NET category on | Points: 40 | Views : 1166
hello,
lets see how to display online users on the webpage, to implement this add new item Global.asax page in your application, follow the below code then...

<%@ Application Language="C#" %>

<script runat="server">

void Application_Start(object sender, EventArgs e)
{
Application["onlineuser"] = 0;

}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
Application.Lock();
Application["onlineuser"] = (int)Application["onlineuser"] + 1;
Application.UnLock();

}

void Session_End(object sender, EventArgs e)
{
Application.Lock();
Application["onlineuser"] = (int)Application["onlineuser"] -1;
Application.UnLock();

}

</script>


then in your master page (design mode) or simple page
write this

Online User: <%=Application["onlineuser"].Tostring()%>

thanks
ankit saxena

Comments or Responses

Login to post response