Webcounter

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Webcounter

 
0
  #1
Feb 12th, 2008
How can I incorporate a web counter (page hit) in ASP.Net to track the number of visitors in my site?
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

Re: Webcounter

 
0
  #2
Feb 12th, 2008
Why don't you track it with statistics?
Anyway, if you really want it, you can use global.asax file for that.

In Application_Start and Application_End event of global.asax set something like this:
  1. Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
  2. Application("Online") = 0
  3. End Sub
  4.  
  5. Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
  6. Application("Online") = 0
  7. End Sub

Then, in Session events use this:
  1. Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
  2. Application("Online") += 1
  3. End Sub
  4.  
  5. Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
  6. Application("Online") -= 1
  7. End Sub

Note: Set sessionstate mode to InProc in the web.config file.

To show it just put this in page:
  1. Online users: <%=Application("Online")%>

Hope this helps, I haven't tested it.
Last edited by ManicCW; Feb 12th, 2008 at 8:59 am. Reason: Added code
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 95
Reputation: ManicCW is an unknown quantity at this point 
Solved Threads: 11
ManicCW's Avatar
ManicCW ManicCW is offline Offline
Junior Poster in Training

Re: Webcounter

 
0
  #3
Feb 12th, 2008
I have just now realized that you need web count, not number of online users.
Well just add +1 in Session_Start event and store sum in text file.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Webcounter

 
0
  #4
Feb 12th, 2008
if you want to see number of visits to individual pages,on page load event of each page, you can run insert statement against a database, include url of the page and ip of the user as columns in case you can group the results by these columns later
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: dilipv is an unknown quantity at this point 
Solved Threads: 4
dilipv dilipv is offline Offline
Light Poster

Re: Webcounter

 
0
  #5
Feb 13th, 2008
hi ebabes,
I think you needed website counter which simply tells number of times website has been visited rather than individual page visit counter. So, you have 2 alternatives to store Visit Count either in to Text File or in to database. I seen one article based on text file, just check the following link.

http://imar.spaanjaars.com/QuickDocID.aspx?QUICKDOC=227

http://www.daniweb.com/forums/thread6566.html

Hope this will help you. If problem persist then feel free to share with me.
Thanks & Regards
Dilip Kumar Vishwakarma
Programmer
.Net Consulting
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Webcounter

 
1
  #6
Feb 13th, 2008
Yes, you can store them within a database or within text, or even within XML.

For research on my websites to see which ones are popular, in which directories, etc. I store all my information in XML files, and upload them once every 15 minutes to the database server. It prevents an unnecessary hit to the database of thousands of times (which can definitely slow your site). I would recommend just storing page hits in an xml file, then upload the information from the xml file to your database server. Then your entire visitor count can be all page hits combined (a SUM command would work). This way it also lets you know which pages are receiving the majority of the traffic.

Its not much work to do, and I believe it to be highly recommended
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Re: Webcounter

 
0
  #7
Feb 14th, 2008
Thanks buddy! Its a big help...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: Webcounter

 
0
  #8
Feb 20th, 2008
Originally Posted by SheSaidImaPregy View Post
Yes, you can store them within a database or within text, or even within XML.

For research on my websites to see which ones are popular, in which directories, etc. I store all my information in XML files, and upload them once every 15 minutes to the database server. It prevents an unnecessary hit to the database of thousands of times (which can definitely slow your site). I would recommend just storing page hits in an xml file, then upload the information from the xml file to your database server. Then your entire visitor count can be all page hits combined (a SUM command would work). This way it also lets you know which pages are receiving the majority of the traffic.

Its not much work to do, and I believe it to be highly recommended
Do you have to read the entire xml file(load xml) to append new record to it? if you have to read the entire document then it may cost more than inserting single record to the database. Is there any simple append to xml method in c#
Last edited by serkan sendur; Feb 20th, 2008 at 10:02 am.
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Webcounter

 
0
  #9
Feb 20th, 2008
Not that I know of serk. Hey, can you tell me how to call an onSelectedIndexChanged event from Page_Load? Trying to help someone but I can't seem to get it right.

The reason I say I would do XML is because most of my sites are heavy on database interaction. This way the server does more processing than the SQL server, which is shared among many. Most of the time the SQL server is backed up while the web server is free and clear. That's why I use XML ^^
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC