1,105,386 Community Members

How to count the no of hits to the website

Member Avatar
yash777
Light Poster
32 posts since May 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
Ramesh S
Posting Pro
584 posts since Jun 2009
Reputation Points: 129 [?]
Q&As Helped to Solve: 113 [?]
Skill Endorsements: 8 [?]
 
0
 
Member Avatar
kameswari
Junior Poster in Training
76 posts since Sep 2008
Reputation Points: 2 [?]
Q&As Helped to Solve: 16 [?]
Skill Endorsements: 0 [?]
 
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.....

dnanetwork
Practically a Master Poster
633 posts since May 2008
Reputation Points: 18 [?]
Q&As Helped to Solve: 106 [?]
Skill Endorsements: 1 [?]
Banned
 
-1
 

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

Member Avatar
sknake
Senior Poster
3,957 posts since Feb 2009
Reputation Points: 1,620 [?]
Q&As Helped to Solve: 747 [?]
Skill Endorsements: 25 [?]
Featured
 
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/

Member Avatar
yash777
Light Poster
32 posts since May 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you all ur support.
It works fine.

Member Avatar
mirzamujib
Newbie Poster
15 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article