国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.Net中的記數(shù)器[初級]

2024-07-10 12:56:11
字體:
供稿:網(wǎng)友

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)
{
//以下為讀取文件,當(dāng)前目錄必須有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>



global.asax文件與文本記數(shù)器的一樣,在此省略;
在images目錄中需要有0-9.gif十張圖片,同樣當(dāng)前目錄需要有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=http://www.163design.net/n/a/images/"+s.substring(i,1)+".gif>";
}
return myimage;
}
</script>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>圖形記數(shù)器</title>
</head>
<body>
<%=g(convert.toint32((application["count"])))%>
</body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 克东县| 彰化市| 永清县| 桂林市| 五大连池市| 天气| 旬阳县| 贡山| 黄骅市| 惠来县| 和硕县| 麻阳| 榆树市| 安化县| 长汀县| 交口县| 甘孜| 荥经县| 桓台县| 乐平市| 兴和县| 扶绥县| 通化市| 商洛市| 油尖旺区| 屯留县| 虞城县| 会泽县| 玉门市| 香港| 甘孜| 察雅县| 民乐县| 石柱| 内乡县| 银川市| 高邮市| 吴川市| 清水县| 绥德县| 无极县|