现在要在一个网站(.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 ();
}
}
}
由于本人从未接触过.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 ();
}
}
}
解决方案 »
- c#导出Excel里面设置单元格问题
- 大家心目中正则的最厉害的一招展示
- 小问题(急)
- 图文混排
- [攒分贴]每日小知识
- 在Timer中实现线程或用线程实现Timer控件?急
- ftp或http协议可以渗透NAT实现P2P功能吗? 在线等……
- WinForms
- 高分求WEB(C#),将图片上传存放到IMAGE字段中,在IMAGE控件(指定大小)里缩略显示的,完整代码??就没人知道怎么写吗?
- C#中怎么实现 只读引用 ?比如c++里面的const MyClass& myc、const MyClass* pmyc
- 怎样判断update成功,以及更新数据的行数,以及锁表时候更新失败?
- PropertyGrid显示"+"的问题
受累 给个具体做法
我没用过.net 不明白应该如何做3Q