Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hi,
I want to display the number of Visitors currently viewing my website. If you know please help me on it.
Posted 10-Jan-13 23:07pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Add a Global.asax file in your project from add new item menu.
 
In Global.asax handle the following events.
 
void Application_Start(object sender, EventArgs e)
    {
        Application["myCount"] = count;
        
    }
 

void Session_Start(object sender, EventArgs e)
    {
        count = Convert.ToInt32(Application["myCount"]); Application["myCount"] = count + 1;
        // Code that runs when a new session is started

    }
 

and in the page load of the page where you want to display the count
 
add the following code.
 
a = Convert.ToInt32((Application["myCount"]));
          Label1.Text = Convert.ToString(a);
 

the label will display the count
 
Remember if you reset the IIS the count will be reset.
 
So better to store it in database and get the data from backend and increment for every session creation and then save it in to database.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

hi,
 
Use this code in global.asax.cs
 
public static int count = 0;
  void Application_Start(object sender, EventArgs e)
  {
    Application["userCount"] = count;
  }
 
  void Session_Start(object sender, EventArgs e)
  {
    count = Convert.ToInt32(Application["myCount"]);
    Application["userCount"] = count + 1;
  }
 
Get this userCount from Application Object & display on a page.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use global.ajax.cs file
You can do this by using the session event
session start add 1
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100