global.asa必须放在网站根目录里
global.asa
----------------------------------------------------------------------
<script language="c#" runat="server">
void Session_OnStart(){
Application.Lock();
Application["whoson"]=Convert.ToInt32(Application["whoson"])+1;
Application.UnLock();
}
void Session_OnEnd(){
Application.Lock();
Application["whoson"]=Convert.ToInt32(Application["whoson"])-1;
Application.UnLock();
}
public void Application_OnStart(){
Application.Lock();
Application["whoson"]=0;
Application.UnLock();
}
</script>
-------------------------------------------------------------------------
count_txt.asp
-------------------------------------------------------------------------
<%@ Page language="C#"%>
<%@ Import Namespace="System.IO"%>
<Script language="C#" runat="server">
public void Page_Load(Object src,EventArgs e)
{
//以下为读取文件,当前目录必须有count.txt这个文件否则会出错
StreamReader sr=File.OpenText(Server.MapPath(".")+"\\count.txt");
Application.Lock();
Application["count"]=sr.ReadLine();
Application["count"]=Convert.ToInt32(Application["count"])+1;
Application.UnLock();
sr.Close();
//建立文件
StreamWriter rw=File.CreateText(Server.MapPath(".")+"\\count.txt");
Application.Lock();
rw.WriteLine(Application["count"]);
Application.UnLock();
rw.Flush(); //写入
rw.Close();
count_1.Text="您是本站第"+Application["count"].ToString()+"位访问者";
}
</Script>
<html>
<head>
</head>
<body>
<hr>
<asp:Label ID="count_1" runat="server"/>
</body>
</html>
本文地址:http://com.8s8s.com/it/it7687.htm