ASP.NET: Page Counter
Notes:

Web Page

<%@ Page Language="C#" Inherits="Counter" src="Counter.aspx.cs" %>
<html>
<head>
<title>Hit counter</title>
</head>
<body>
<p>You are visitor number <%=Val()%></p>
</body>
</html>

 

Code Behind

using System;
using System.Web.UI;

public class Counter : Page {

public int Val() {
Application.Lock();
object ctr = Application["hitCounter"];
int n = ctr == null ? 0 : (int)ctr;
Application["hitCounter"] = ++n;
Application.UnLock();
return n;
}
}

 

 

No votes yet
Related Links:ASP.NET: Image AlbumASP.NET: Displaying HTTP Request ParametersASP.NET: User ControlsASP.NET: Validity ChecksASP.NET: Validity Checks
© Copyright 2008. All Rights Reserved.