Home   Cover Cover Cover Cover
 

Besucherzähler

Web-Seite

../../solutions/6/Counter.aspx
<%@ 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>

Hintergrundcode

../../solutions/6/Counter.aspx.cs
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;
  }
}

Ausführung

Klicken Sie hier.