Webcounter
How can I incorporate a web counter (page hit) in ASP.Net to track the number of visitors in my site?
ebabes
Junior Poster in Training
73 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
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:
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("Online") = 0
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
Application("Online") = 0
End Sub
Then, in Session events use this:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("Online") += 1
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Application("Online") -= 1
End Sub
Note: Set sessionstate mode toInProc in the web.config file.
To show it just put this in page:
Online users: <%=Application("Online")%>
Hope this helps, I haven't tested it.
ManicCW
Junior Poster in Training
95 posts since Nov 2005
Reputation Points: 13
Solved Threads: 11
I have just now realized that you need web count, not number of online users. :D
Well just add +1 in Session_Start event and store sum in text file.
ManicCW
Junior Poster in Training
95 posts since Nov 2005
Reputation Points: 13
Solved Threads: 11
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
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
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
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Thanks buddy! Its a big help...
ebabes
Junior Poster in Training
73 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
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#
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
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 ^^
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68