[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

asp.net 3.5 hit counter

Posted on 2011-03-20
4
Medium Priority
?
579 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

656 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