Hit Counter and Visitor Online of ASP.NET Hit Counter class Counter { private string sCounterPage; private string sCounter; private int iCounter; public Counterstring sPath { sCounterPag
Trang 1Hit Counter and Visitor Online of ASP.NET
Hit Counter
class Counter
{
private string sCounterPage;
private string sCounter;
private int iCounter;
public Counter(string sPath)
{
sCounterPage=sPath;
}
public int ReadFile()
{
StreamReader objStreamReader;
objStreamReader=File.OpenText(sCounterPage);
sCounter=objStreamReader.ReadToEnd();
iCounter=(int)(sCounter);
iCounter +=1;
Trang 2objStreamReader.Close();
Return iCounter;
}
public void WriteFile()
{
StreamWrite objStreamWrite;
objStreamWrite=File.CreateText(sCounterPage); objStreamWrite.Write(iCounter.ToString());
objStreamWrite.Close();
}
}
Visitor Online
Sub Application_OnStart(Object sender, EventArgs e) {
Application["VistorOnline"]=0;
}
Sub Sessioin_OnStart(Object sender, EventArgs e)
Trang 3{
Session.TimeOut=
Application.Lock;
Application["VisitorOnline"]=Application + 1; Application.UnLock;
}
Sub Session_OnEnd(Object sender, EventArgs e) {
Application.Lock;
Application["VisitorOnline"]=Application - 1; Application.UnLock;
}