站点计数器
来源:互联网 发布:菜谱设计软件 编辑:程序博客网 时间:2024/04/27 17:42
新建一个网站,然后在Default.aspx里添加代码如下:
1<script language="c#" runat="server">
2 private void Page_Load(object sender, System.EventArgs e)
3 {
4 if (!IsPostBack)
5 GlobalGraph(MyPanel);
6 }
7 void GlobalGraph(Panel Container)
8 {
9 Label lbl;
10 Label lbl2;
11 string count;
12 lbl = new Label();
13 lbl2 = new Label();
14 lbl.Text = "该站点已被访问次数:";
15 Container.Controls.Add(lbl);
16 count = Application["Counter"].ToString();
17 for (int i = 0; i < count.Length; i++)
18 {
19 lbl2.Text=count.Substring(i, 1);
20
21 Container.Controls.Add(lbl2 ); //加载到控件容器
22 }
23 }
24 </script>
25
26<body style="background-color:White">
27<p><strong style=" font-family:@楷体_GB2312">Welcome to you!</strong> </p>
28 <form id="form1" runat="server">
29 <div>
30 <asp:Panel id="MyPanel" runat="server" width="50%" BorderColor="#C0FFC0" BorderStyle="Groove"></asp:Panel>
31 </div>
32 </form>
33</body>
添加新项Global.asax文件,先声名,添加代码如下:2 private void Page_Load(object sender, System.EventArgs e)
3 {
4 if (!IsPostBack)
5 GlobalGraph(MyPanel);
6 }
7 void GlobalGraph(Panel Container)
8 {
9 Label lbl;
10 Label lbl2;
11 string count;
12 lbl = new Label();
13 lbl2 = new Label();
14 lbl.Text = "该站点已被访问次数:";
15 Container.Controls.Add(lbl);
16 count = Application["Counter"].ToString();
17 for (int i = 0; i < count.Length; i++)
18 {
19 lbl2.Text=count.Substring(i, 1);
20
21 Container.Controls.Add(lbl2 ); //加载到控件容器
22 }
23 }
24 </script>
25
26<body style="background-color:White">
27<p><strong style=" font-family:@楷体_GB2312">Welcome to you!</strong> </p>
28 <form id="form1" runat="server">
29 <div>
30 <asp:Panel id="MyPanel" runat="server" width="50%" BorderColor="#C0FFC0" BorderStyle="Groove"></asp:Panel>
31 </div>
32 </form>
33</body>
<%@ Import Namespace="System.Web.SessionState" %>
<%@ Import Namespace="System.IO" %>
在相应位置添加代码如下:<%@ Import Namespace="System.IO" %>
void Application_Start(object sender, EventArgs e)
{
StreamReader rd = new StreamReader(Server.MapPath("counter.txt"));
int nNum = int.Parse(rd.ReadLine());
Application.Lock();
Application["Counter"] = nNum;
Application.UnLock();
rd.Close();
}
void Session_Start(object sender, EventArgs e)
{
Application.Lock();
Application["Counter"] = Convert.ToInt32(Application["Counter"]) + 1;
Application.UnLock();
//写入
StreamWriter sw = new StreamWriter(Server.MapPath("counter.txt"), false);//false为不追加
sw.WriteLine(Application["Counter"]);
sw.Close();
}
void Session_End(object sender, EventArgs e)
{
//写入
StreamWriter sw = new StreamWriter(Server.MapPath("counter.txt"),false);//false为不追加
sw.WriteLine(Application["Counter"]);
sw.Close();
}
最后你还要在程序目录里新建Counter.txt文件,就OK了 {
StreamReader rd = new StreamReader(Server.MapPath("counter.txt"));
int nNum = int.Parse(rd.ReadLine());
Application.Lock();
Application["Counter"] = nNum;
Application.UnLock();
rd.Close();
}
void Session_Start(object sender, EventArgs e)
{
Application.Lock();
Application["Counter"] = Convert.ToInt32(Application["Counter"]) + 1;
Application.UnLock();
//写入
StreamWriter sw = new StreamWriter(Server.MapPath("counter.txt"), false);//false为不追加
sw.WriteLine(Application["Counter"]);
sw.Close();
}
void Session_End(object sender, EventArgs e)
{
//写入
StreamWriter sw = new StreamWriter(Server.MapPath("counter.txt"),false);//false为不追加
sw.WriteLine(Application["Counter"]);
sw.Close();
}
- 站点计数器
- 站点计数器
- [ASP] 创建站点计数器
- 实现站点计数器的用户控件
- SharePoint站点点击量计数器Web部件
- asp.net中用C#实现站点计数器用户控件
- asp.net中用C#实现站点计数器用户控件
- ASP.Net中用C#实现站点计数器用户控件
- asp.net中用C#实现站点计数器用户控件
- asp.net中用C#实现站点计数器用户控件[转]
- ASP.Net中用C#实现站点计数器用户控件
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- 计数器
- frameset 使用心得
- 记久违的关爱(之一)
- Session 详解
- 儲存過程萬能分頁
- 在两个页面之间传递信息
- 站点计数器
- 启动Erlana: Erlang Analytics项目
- dd命令复制硬盘
- (创建型模式)Singleton 单件模式
- "代购"电子商务新模式
- ASP.NET2.0
- C#,数据库读写XML
- 我为什么选择了Erlang?
- 国际标准分类法ICS