global.asax文件与文本记数器的一样,在此省略;
在images目录中需要有0-9.gif十张图片,同样当前目录需要有count.txt这个文件,否则会出错
count_pic.aspx
———————————————————————————–
<%@ page language="c#" contenttype="text/html" responseencoding="gb2312" %>
<%@ import namespace="system.io"%>
<script language="c#" runat="server">
public void page_load(object src,eventargs e)
{
//以下为读取文件
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();
}
public string g(int counter)
{
string myimage="";
string s=counter.tostring();
//strreplace=replace(strreplace,chr[92]);
for(int i=0;i<=s.length-1;i++)
{
myimage =myimage+"<img src=./images/"+s.substring(i,1)+".gif>";
}
return myimage;
}
</script>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>图形记数器</title>
</head>
<body>
<%=g(convert.toint32((application["count"])))%>
</body>
</html>
