0

I am working on a MVC website, and I want to know the number of user visits my website has.

I am using below code in Application_Start() in global.asax.cs:

protected void Application_Start()
{
    Application["Totaluser"] = 0;
    AreaRegistration.RegisterAllAreas();

    WebApiConfig.Register(GlobalConfiguration.Configuration);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

protected void Session_Start()
{
    Application.Lock();
    Application["Totaluser"] = (int)(Application["TotalUser"] + 1);
    Application.Unlock();
}

But when I am opening the website freshly, it is showing as 1 all the time. How do I maintain the count all the time, so that it will show the number of hits correctly?

trashr0x
  • 6,457
  • 2
  • 29
  • 39
Abhijit.P
  • 39
  • 1
  • 4
  • 3
    I imagine you'd want to store this information in something a little more persistent, such as a database. – David Nov 22 '16 at 12:28
  • 3
    I'd recommend using something that is designed to monitor/record page views and user counts, such as Google Analytics or something like that. – Luke Nov 22 '16 at 12:28
  • 2
    Images and screenshots can be a nice addition to a post, but please make sure the post is still clear and useful without them. If you post images of code or error messages make sure you also copy and paste or type the actual code/message into the post directly. – trashr0x Nov 22 '16 at 12:30
  • I just had fun writing your code out from that image :o) – Luke Nov 22 '16 at 12:34

0 Answers0