Wrox Programmer Forums
|
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 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 November 2nd, 2003, 12:53 AM
Authorized User
 
Join Date: Nov 2003
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
 
Old November 2nd, 2003, 10:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.
 
Old November 2nd, 2003, 02:24 PM
Authorized User
 
Join Date: Nov 2003
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
 
Old November 2nd, 2003, 03:09 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.





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





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