Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 2nd, 2003, 12:53 AM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page Hit Counter


How do I correctly code a Site Hit Counter for the number of times (sessions) a page has been visited.
Reference is Professional ASP.NET 1.0, pages 610 and 611.
In Global.aspx.cs I've inserted the second line with intHitCount
    public class Global : System.Web.HttpApplication {
        protected int intHitCount = 0;
and:

    protected void Session_Start(Object sender, EventArgs e) {
        intHitCount += 1;
        Session["SessionHitCounter"] = intHitCount.ToString();
    }

Then in the Welcome.aspx page file I have:
<form id="Form1" method="post" runat="server">
<h3 class="title"><i>Welcome! You are visitor number</i><br>
<asp:label id="lblHitNo" runat="server" Width="129px" BackColor="#dbdbdd" ForeColor="#ef0063"></asp:label><br>
<i>since November 2003</i></h3>
</form>

and in the Welcome.aspx.cs file I have:
public class WelcomeForm : System.Web.UI.Page {
    protected System.Web.UI.WebControls.Label lblHitNo;
    protected System.Web.UI.HtmlControls.HtmlForm Form1;

    private void Page_Load(object sender, System.EventArgs e) {
        lblHitNo.Text = (string)Session["SessionHitCounter"];
    }


and this does NOT work. Strangely, it counts up to about 85 and then starts over.


Sandy

Sandy
__________________
Sandy
Reply With Quote
  #2 (permalink)  
Old November 2nd, 2003, 10:45 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Sandy,

Are you running Windows Server 2003? In II6 the option to recycle your Web application every X minutes / hours is on by default. This may cause the loss of information.

If that's the case, you may need to disable this option, or store the counters in a durable location, like a database or text-file.

Can you please post your posts in the relevant forum? This forum is for Classic ASP and not for .NET. This is also true for the cross posts you made in the HTML forum.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #3 (permalink)  
Old November 2nd, 2003, 02:24 PM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Thank you so much for responding.
1. Which topic is the correct topic for ASP.NET 1.0?
2. My development platform is XP Professional, Version 2002, Service Pack 1, with IIS 5.1 and SQL Server 2000. I think the Web Server it's on is Windows Server 2000 - I'll check Monday morning and let you know in the correct topic.




Sandy
Reply With Quote
  #4 (permalink)  
Old November 2nd, 2003, 03:09 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

It all depends on the topic you're posting, but ASPX Beginners or ASPX Professional are good candidates:

http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/
http://p2p.wrox.com/forum.asp?FORUM_ID=50

When you say it counts to 85, how do you get to that count? Do you continuously refresh the page, or do you wait a while. And if you open the page in a fresh browser instance, does it take on the old value, or does it start at 1?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add a hit counter in asp.net page narayannayakmca ASP.NET 1.0 and 1.1 Basics 1 January 3rd, 2007 01:11 PM
A Hit Counter, PLEASE HELP !!!!! ARD_40 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 23rd, 2006 06:25 AM
Hit Counter Help! NeilS21 Classic ASP Databases 4 April 29th, 2005 06:59 AM
hit counter gumgak Classic ASP Basics 2 November 2nd, 2003 12:44 AM



All times are GMT -4. The time now is 12:54 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.