现在要在一个网站(.net的)上加一个计数器。我从网上下载了一个.net的计数器(共4个文件,counter.txt、Global.asax、Global.asax.cs、WebForm1.aspx),放到网站空间里,直接访问webform1.aspx正常。但是不知道如何放到网站的页面上,我想放到网站的foot.aspx里面。我试过直接在foot.aspx文件里 <!--#include file="webform1.aspx"-->也不行。
由于本人从未接触过.net,所以问出这么弱弱的问题,见笑。希望大家不吝赐教。 给我个详细的做法,谢谢!~把我下载的计数器的代码贴出来,
[WebForm1.aspx]:
<%@ Page language="c#"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript (ECMAScript)">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<FONT face="宋体">您是第<%=Application["counter"]%>位访问者!</FONT>
</form>
</body>
</HTML>[Global.asax]:
<%@ Application Src="Global.asax.cs" Inherits="counter2.Global" %>[Global.asax.cs]:
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.IO ;namespace counter2 
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(Object sender, EventArgs e)
{
uint count=0;
StreamReader srd;
string file_path=Server.MapPath ("counter.txt");
srd=File.OpenText (file_path);
while(srd.Peek ()!=-1)
{
string str=srd.ReadLine ();
count=UInt32.Parse (str);
}
object obj=count;
            Application["counter"]=obj;
srd.Close ();            
}
 
protected void Session_Start(Object sender, EventArgs e)
{
Application.Lock ();
//数值累加,注意这里使用了装箱(boxing)
uint jishu=0;
jishu=(uint)Application["counter"];
jishu=jishu+1;
object obj=jishu;
Application["counter"]=obj;
//将数据记录写入文件
string file_path=Server.MapPath ("counter.txt");
StreamWriter fs=new StreamWriter(file_path,false); 
fs.WriteLine (jishu);
fs.Close ();
        
Application.UnLock ();
} protected void Application_BeginRequest(Object sender, EventArgs e)
{ } protected void Application_EndRequest(Object sender, EventArgs e)
{ } protected void Session_End(Object sender, EventArgs e)
{ } protected void Application_End(Object sender, EventArgs e)
{

//装箱
uint js=0;
js=(uint)Application["counter"];
//object obj=js;
//Application["counter"]=js;
//将数据记录写入文件
string file_path=Server.MapPath ("counter.txt");
StreamWriter fs=new StreamWriter(file_path,false); 
fs.WriteLine(js);
fs.Close ();
}
}
}