I wanna share…

Posts tagged ‘application users’

To get number of online visitors(current) to your website(ASP NET).

Showing Current number of user in online is common in the part of developing a web site.

How to achieve that??? very simple.

1. Add Global.asax file to your application(web)

2. Add this code…

void Application_Start(object sender, EventArgs e)
{
Application[“Users”] = 0;
}

void Session_Start(object sender, EventArgs e)
{
Application.Lock();
Application[“Users”] = (int)Application[“Users”] + 1;
Application.UnLock();
}

void Session_End(object sender, EventArgs e)
{
Application.Lock();
Application[“Users”] = (int)Application[“Users”] – 1;
Application.UnLock();
}

3. In the web.config file write this code…

<system.web>
<sessionState mode=”InProc” cookieless=”false” timeout=”15″ />
</system.web>

 

4. Use this code in your Home Page

No. of users in online ::::: <%= Application[“Users”].ToString() %>

 

5. Build and Run the application.

Hope it help you….