Find Number of visitors for a site in ASP.NET MVC using C#

316 views Asked by At

I am trying to find number of visitors for a site using Application.

My Global.asax.cs looks like this:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

        //Added for version tracking
        Application["ActiveUsers"] = 0;
    }

And my Controller I added following code:

string i =  Application["ActiveUsers"].ToString();

But I am getting a error "Application' does not exist in the current context" .

Am I missing any namespace or is Application doesn't work in Controller level.(I don't see error in Golbal.asax.cs)

Thanks.

1

There are 1 answers

0
mxmissile On BEST ANSWER

You can access that via:

int i = HttpContext.Application["ActiveUsers"] as int;