Solved

asp.net 3.5 hit counter

Posted on 2011-03-20
4
574 Views
Last Modified: 2012-06-21
Hi experts

Using asp.net 3.5 with vb.net as the code-behind, has anyone got any examples of a hit counter, I need the counter to increment for each visitor to the site and not every time the page is loaded, hope somebody can help.
0
Comment
Question by:dizzycat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:AkAlan
ID: 35175896
When users hit your site, do they have to log in or do you need a counter for the interface page?
0
 

Author Comment

by:dizzycat
ID: 35175936
I would just like a counter for the interface page, there is no log-in on my site.
0
 
LVL 6

Accepted Solution

by:
AkAlan earned 500 total points
ID: 35175969
Here is an example I found here:
http://www.daniweb.com/web-development/aspnet/threads/5145


PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load

IfNot Page.IsPostBack Then
Dim nCount As Int32 = 0
nCount = GetCounterValue()
lblTest.Text = nCount.ToString()
EndIf
EndSub

PrivateFunction GetCounterValue() As Int32

Dim ctrFile As StreamReader
Dim ctrFileW As FileStream
Dim sw As StreamWriter
Dim strPath AsString = Server.MapPath("indexcount.txt")
Dim strCounterContents AsString
Dim nCounter As Int32
 
If (File.Exists(strPath)) Then
ctrFile = File.OpenText(strPath)
strCounterContents = ctrFile.ReadLine().ToString()
ctrFile.Close()
nCounter = Convert.ToInt32(strCounterContents)
Else
nCounter = 0
EndIf
nCounter += 1
ctrFileW = New FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write)
sw = New StreamWriter(ctrFileW)
sw.WriteLine(Convert.ToString(nCounter))
sw.Close()
ctrFileW.Close()
Return nCounter
EndFunction

  
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load

IfNot Page.IsPostBack Then
Dim nCount As Int32 = 0
nCount = GetCounterValue()
lblTest.Text = nCount.ToString()
EndIf
EndSub

PrivateFunction GetCounterValue() As Int32

Dim ctrFile As StreamReader
Dim ctrFileW As FileStream
Dim sw As StreamWriter
Dim strPath AsString = Server.MapPath("indexcount.txt")
Dim strCounterContents AsString
Dim nCounter As Int32
 
If (File.Exists(strPath)) Then
ctrFile = File.OpenText(strPath)
strCounterContents = ctrFile.ReadLine().ToString()
ctrFile.Close()
nCounter = Convert.ToInt32(strCounterContents)
Else
nCounter = 0
EndIf
nCounter += 1
ctrFileW = New FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write)
sw = New StreamWriter(ctrFileW)
sw.WriteLine(Convert.ToString(nCounter))
sw.Close()
ctrFileW.Close()
Return nCounter
EndFunction

Open in new window


0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 35175993
buddy just go for http://www.hit-counts.com/ ( such types of links, get you site link register it, and get visitor no automatically calculated by this site. u wiil get a link  paste the javascript wherever u want to print the visitor no like eg


 <tr>
 <td align ="center">Visitor No.      </td>
 <td align ="left" style="text-align: left">
  <img src='http://www.hit-counts.com/counter.php?t=10&digits=9&ic=72000&cid=74644' border='0' alt=''>
</td>
</tr>



the image source u will get after registration (underlined ) its free and easy to manage, with various designs available.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp Google Map 2 57
looking for an ASP.net report designer 4 41
Unexpected End of File 11 54
Make a website not indexable by google 6 28
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question