943,810 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1181
  • ASP.NET RSS
Feb 12th, 2008
0

Webcounter

Expand Post »
How can I incorporate a web counter (page hit) in ASP.Net to track the number of visitors in my site?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007
Feb 12th, 2008
0

Re: Webcounter

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:
ASP.NET Syntax (Toggle Plain Text)
  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:
ASP.NET Syntax (Toggle Plain Text)
  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:
ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005
Feb 12th, 2008
0

Re: Webcounter

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.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
ManicCW is offline Offline
95 posts
since Nov 2005
Feb 12th, 2008
0

Re: Webcounter

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
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Feb 13th, 2008
0

Re: Webcounter

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
Reputation Points: 10
Solved Threads: 4
Light Poster
dilipv is offline Offline
30 posts
since Feb 2008
Feb 13th, 2008
1

Re: Webcounter

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
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Feb 14th, 2008
0

Re: Webcounter

Thanks buddy! Its a big help...
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007
Feb 20th, 2008
0

Re: Webcounter

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.
Featured Poster
Reputation Points: 854
Solved Threads: 127
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Feb 20th, 2008
0

Re: Webcounter

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 ^^
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How do you search all current sessions on the sever, or within the website?
Next Thread in ASP.NET Forum Timeline: How to calculate date with integer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC