国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 雅江县| 翼城县| 玉溪市| 桦甸市| 浮梁县| 清徐县| 通许县| 威海市| 连平县| 东山县| 吉水县| 鲁山县| 梨树县| 灌阳县| 丰都县| 普陀区| 白水县| 洛宁县| 靖西县| 读书| 景洪市| 涿州市| 罗源县| 剑阁县| 井研县| 兴仁县| 和田市| 榆树市| 正阳县| 汉沽区| 浮山县| 通道| 镇远县| 永吉县| 墨竹工卡县| 东明县| 庆元县| 信宜市| 信丰县| 宜兰市| 巴楚县|