Building a Page Counter (Image) Using JScript.Net
page 3 of 6
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28312/ 71

The JScript.Net Code, Part 1

First off, we need to create the functions which will read and save the counter (increase counter before if new visitor). Copy the following code into a new text file and save the file as counter.aspx:


<%@ Page Language="JScript"%>
<%@ Import Namespace="System.IO" %>

<% var FilePath:String = Server.MapPath("\\") + "counter.txt";

function getCounter():String
var SR:StreamReader = File.OpenText(FilePath,FileMode.Open);
var Counter:String = SR.ReadLine().ToString();

var Cookie:HttpCookie;
Cookie = Request.Cookies("OldVisitor");

var CounterInt:int = Convert.ToInt32(Counter);
Counter = Convert.ToString(CounterInt);

var FS:FileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Write);
var Text:StreamWriter = new StreamWriter(FS);

Cookie = new HttpCookie("OldVisitor","true");
Cookie.Expires = DateTime.Now.AddSeconds(120);

return Counter;

End Sub


You should now place the counter.aspx in your root folder (i.e. c:\InetPub\wwwroot) on your Internet Information Server. Also, create a file called counter.txt and set the read/write security options to full access for the user your are running under IIS. Open the counter.txt file, write a number (i.e. 999) and save the file.

When you now open the URL http://localhost/counter.aspx in your browser, you will see a text counter. The counter has already add one count to the number you put in counter.txt.

View Entire Article

User Comments

Title: Firefox :s   
Name: Remi
Date: 2007-04-07 9:04:44 AM
Works great in IE! Only Firefox has some problems displaying the image. It just shows a range of weird characters :s.
Title: SPA   
Name: dheeraj Ahuja
Date: 2005-10-28 3:07:28 AM
this is gud article and it helped me alot
now wht i want is to call a server side from client routine with refering any "src",
is there any way

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-28 6:52:53 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search