p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   hit counter (http://p2p.wrox.com/showthread.php?t=1470)

gumgak July 9th, 2003 07:49 PM

hit counter
 
I am using ASP.NET with C#.
i once saw the code that generates hit count using server control / session. it was really simple.

can anyone help me with this?

gumgak July 10th, 2003 01:07 PM

Following code works well for the session. however i need to find out how to track the number of visitors using web.conf. can anyone help?

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.ComponentModel" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.SessionState" %>
<%@ Import Namespace="System.IO" %>

<script language="C#" runat="server" >
    void Page_Load(object sender, System.EventArgs e)
    {
        int count = 0;
        if (!(Page.IsPostBack)){
            count = SessionHitCounter();
        }
        SessionCount.Text = Convert.ToString(count);
    }

    public int SessionHitCounter()
    {
       if (Session["HitCounter"] == null) {
          Session["HitCounter"] = 1;
       }
       else {
          Session["HitCounter"] = ((int) Session["HitCounter"]) + 1;
       }
       return ((int) Session["HitCounter"]);
    }

     void EnterBtn_Click(Object Src, EventArgs E)
    {
          // Populate the text box with the results from the call to the XML Web service method.
          int i = SessionHitCounter();
          SessionCount.Text = Convert.ToString(i);
    }

</script>

<HTML>
<HEAD>
<TITLE>counter test</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<BODY>
    <form runat="server" id="Form1">
        <asp:button text="Bump Up Counter" Onclick="EnterBtn_Click" runat=server ID="Button1" NAME="Button1"/>
        <p>
        hit counter:
        <ASP:LABEL ID="SessionCount" runat="server"></ASP:LABEL>
    </form>
</BODY>
</HTML>

shmacgregor November 2nd, 2003 12:44 AM

Have you found an answer?
I have the same question and have entered the code in that question which is now one the Active Topics. Please look at it. I'm using a Session State object on the Global.aspx.cs page.
Where did you declare count, and SessionCount, and HitCount?


Sandy


All times are GMT -4. The time now is 04:11 PM.

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