Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2008, 01:49 PM
Authorized User
 
Join Date: Aug 2006
Location: bishops itchington,southam, warwickshire, United Kingdom.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Has anyone got a visitor counter ?

looking around at the various sites here it seems that nobody here
has put a visitor counter on any of the sites, is there a reason for this ?.

I have tried code in the global.asax with some degree of success but
it's still not working properly.

Any idea's guys how to go about the best way of implementing this.

 
Old January 30th, 2008, 03:42 PM
Registered User
 
Join Date: Jan 2008
Location: Ruwi, Ruwi, Oman.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sm.ibrahim
Default

Hi! Dear here comes your questions working solution

here comes the global.asa file save this file with the name global.asa
---------------------------------------------------------------------
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">

Sub Application_OnStart
    ' Set our user count to 0 when we start the server
    Application("ActiveUsers") = 0
End Sub

Sub Session_OnStart
    ' Change Session Timeout to 20 minutes (if you need to)
    Session.Timeout = 20
    ' Set a Session Start Time
    ' This is only important to assure we start a session
    Session("Start") = Now
    ' Increase the active visitors count when we start the session
    Application.Lock
        Application("ActiveUsers") = Application("ActiveUsers") + 1
    session("date")=now()
    Application.UnLock
End Sub

Sub Session_OnEnd
    ' Decrease the active visitors count when the session ends.
    Application.Lock
        Application("ActiveUsers") = Application("ActiveUsers") - 1
    Application.UnLock



Set ObjMyFile = CreateObject("Scripting.FileSystemObject")
Set OpenMyFile = ObjMyFile.OpenTextFile(Server.MapPath("last-update.txt"))
MyFileValue = OpenMyFile.ReadLine
OpenMyFile.Close

    If DateDiff("h",MyFileValue,NOW) > 6 Then

           ' Here you would put any code you need to run
           ' do not surround the code with <% %> tags
           ' For example you might run a database query that checks for expired accounts

            Set WriteMyFile = ObjMyFile.CreateTextFile(Server.MapPath("last-update.txt"))
            WriteMyFile.WriteLine(NOW)
            WriteMyFile.Close

    End if


End Sub

</SCRIPT>
---------------------------------------------------------------------

and the to check the active users is the below file save it with the name samplepage.asp and the most imp thing is both the file should be in the same location then only this ll work

---------------------------------------------------------------------
<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>Active Sessions</TITLE>
</HEAD>
<BODY>

<B><%= Application("ActiveUsers") %> Active Users</B>
<br>
<B><%= session("start") %> was Session Started</B>
</BODY>
</HTML>
---------------------------------------------------------------------

that's it N-joy Coding


with regards
ibrahim sm

With Regards
sm ibrahim
 
Old January 31st, 2008, 02:14 PM
Authorized User
 
Join Date: Aug 2006
Location: bishops itchington,southam, warwickshire, United Kingdom.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Heck.....does anyone know what this is in C# ?

 
Old February 2nd, 2008, 08:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code posted above was written in VBScript for the global.asa file. In ASP.NET we typically don't use VBScript and we use global.asax instead. We can put C# code in that file, and we have similar events to those used above. We also have application state that could be used to track the number of online users, but of course, you'll lose that when the application resets.

To track the number of hits on a specific page you could either update a server-side file, as the code above did, or else you can keep the counter in the DB. Or you can let an outside service do it for you.

I prefer to hit count all of my pages separately and since I'm a lazy programmer, I decided to let Google Analytics track the hits for me. That's a free service and all you have to do is to drop some JavaScript into your pages. You can set up a free account and visit them to get neat graphs that show a lot of good information about your users.

http://www.google.com/analytics/

The only thing it can't track is file downloads. The IIS logs have all that info, and a whole lot more, and the free awstats program does a great job of making cool reports based on that log info:

http://awstats.sourceforge.net/

If you have a shared hosting site, then that specific provider will offer this kind of log graphing functionality and it's normally free.

Eric

 
Old February 5th, 2008, 04:01 AM
Authorized User
 
Join Date: Aug 2006
Location: bishops itchington,southam, warwickshire, United Kingdom.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's great, you have saved me some headaches there.

Thanks guys.





Similar Threads
Thread Thread Starter Forum Replies Last Post
visitor duration per page esemerda Pro PHP 2 September 8th, 2005 01:38 PM
Counter tp194 Javascript 1 September 2nd, 2004 08:02 AM
HTTP_REFERER Tester Sometimes Redirects OK Visitor markw707 Classic ASP Basics 4 August 21st, 2003 11:41 PM
counter Adam H-W Classic ASP Basics 15 August 15th, 2003 11:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.