页面记数器

来源:互联网 发布:windows批处理命令教程 编辑:程序博客网 时间:2024/06/04 08:37

login.aspx

<%@ Page language="c#" Codebehind="Login.aspx.cs" AutoEventWireup="false" Inherits="ASPNETPage.Login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm1</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <asp:Label id="lbInfo" style="Z-INDEX: 101; LEFT: 216px; POSITION: absolute; TOP: 111px" runat="server" Width="256px"></asp:Label>
  </form>
 </body>
</HTML>
login.aspx.cs

                                                                                                                                               

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ASPNETPage
{
 /// <summary>
 /// WebForm1 的摘要说明。
 /// </summary>
 public class Login : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Label lbInfo;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   lbInfo.Text = "您是第" + Application["Counter"] + "位访问者";
  }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion
 }
}

 global文件

using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.IO;
namespace ASPNETPage
{
 /// <summary>
 /// Global 的摘要说明。
 /// </summary>
 public class Global : System.Web.HttpApplication
 {
  public Global()
  {
   InitializeComponent();
  } 
  
  protected 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();
  }
 
  protected 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();
  }

  protected void Application_BeginRequest(Object sender, EventArgs e)
  {

  }

  protected void Application_EndRequest(Object sender, EventArgs e)
  {

  }

  protected void Application_AuthenticateRequest(Object sender, EventArgs e)
  {

  }

  protected void Application_Error(Object sender, EventArgs e)
  {

  }

  protected void Session_End(Object sender, EventArgs e)
  {

  }

  protected void Application_End(Object sender, EventArgs e)
  {
//   //写入
//   StreamWriter sw = new StreamWriter(Server.MapPath("counter.txt"),false);//false为不追加
//   sw.WriteLine(Application["Counter"]);
//   sw.Close();
  }
   
  #region Web Form Designer generated code
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
  }
  #endregion
 }
}

 

                                                               

原创粉丝点击