1.11M Members

How to count the no of hits to the website

 
0
 

Hello ,
I would like to count the no of hits to my website.
How do i do it?
whether I need to code it in Global.asax file in application on start ??????
Reply

 
0
 

Hello ,
I would like to count the no of hits to my website.
How do i do it?
whether I need to code it in Global.asax file in application on start ??????
Reply

Hi you can place the code in Global.asax file and u need to call that variable in the aspx page. Example:

void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["Visitors"] = 0;

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        Application.Lock();

        Application["Visitors"] = Convert.ToInt32(Application["Visitors"]) +1;
        Application.UnLock();
    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application["Visitors"] = Convert.ToInt32(Application["Visitors"])-1;

    }

In the aspx file u need to call that variable as follow:

protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text =  Application["Visitors"].ToString();
       
    }

*** do reply whether it solves ur problem or not.....

 
-1
 

use application variable....works... 100%

 
0
 

use application variable....works... 100%

Application variables are not persisted and you will lose the count data.

You can also take a look at a free application called smarter stats for weblog analysis. There is a lot more information to be had from IIS log files then the number of times your page was accessed. You have to take in to account spiders that crawl your site.

SmartStats: http://www.smartertools.com/

 
0
 

Thank you all ur support.
It works fine.

 
0
 

gr8 work...

Hi you can place the code in Global.asax file and u need to call that variable in the aspx page. Example:

void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["Visitors"] = 0;

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        Application.Lock();

        Application["Visitors"] = Convert.ToInt32(Application["Visitors"]) +1;
        Application.UnLock();
    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        Application["Visitors"] = Convert.ToInt32(Application["Visitors"])-1;

    }

In the aspx file u need to call that variable as follow:

protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text =  Application["Visitors"].ToString();
       
    }

*** do reply whether it solves ur problem or not.....

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article