hit counter, visitor ?

thanh phuoc asked on July 5, 2015 21:13

Hi,

I can't count visitor, current online, i have add code in Global.aspx.cs, but fail

    public class Global : CMSHttpApplication
{
    #region "Methods"

    public Global()
    {
#if DEBUG
        // Set debug mode
        SystemContext.IsWebProjectDebug = true;
#endif

        ApplicationEvents.PreInitialized.Execute += EnsureDynamicModules;
    }


    /// <summary>
    /// Ensures that modules from the App code assembly are registered.
    /// </summary>
    private static void EnsureDynamicModules(object sender, EventArgs e)
    {
        ModuleEntryManager.EnsureModule<CMSModuleLoader>();

        var discovery = new ModuleDiscovery();
        var assembly = typeof(CMSModuleLoader).Assembly;
        foreach (var module in discovery.GetModules(assembly))
        {
            ModuleEntryManager.EnsureModule(module);
        }
    }
    //void Application_BeginRequest(object sender, EventArgs e)
    //{
    //    HttpApplication app = sender as HttpApplication;
    //    if (app.Request.Path.IndexOf("FriendlyPage.aspx") > 0)
    //    {
    //        app.Context.RewritePath("/gioi-thieu/ve-cong-ty.aspx");
    //    }
    //}
    #endregion

    void Application_Start(object Sender, EventArgs E)
    {

        // Set our user count to 0 when we start the server

        Application["ActiveUsers"] = 0;

    }

    void Session_Start(object Sender, EventArgs E)
    {

        Session["Start"] = DateTime.Now;

        Session.Timeout = 1;

        Application.Lock();

        Application["ActiveUsers"] = (int)Application["ActiveUsers"] + 1;

        Application.UnLock();

    }

    void Session_End(object Sender, EventArgs E)
    {

        Application.Lock();

        Application["ActiveUsers"] = (int)Application["ActiveUsers"] - 1;

        Application.UnLock();

        Session.Clear();

        Session.Remove("Start");

    }
}


Help me

Correct Answer

Roman Hutnyk answered on July 6, 2015 03:18

Kentico allows you to do that without writing any code.

Web Analytics will track page visits for you, just make sure it is enabled under Settings -> Online Marketing -> Web analytics. Tracking of online users could be enabled in Settings -> Security & Membership -> Online Users section.

Hope this helps.

0 votesVote for this answer Unmark Correct answer

Recent Answers


thanh phuoc answered on July 8, 2015 00:50

Thanks Roman Hutnyk, I want show info to the page .aspx ?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.