利用ASP.NET制作简单计数器的例子

 1 None.gif using  System;
 2 None.gif using  System.Collections;
 3 None.gif using  System.ComponentModel;
 4 None.gif using  System.Web;
 5 None.gif using  System.Web.SessionState;
 6 None.gif using  System.Data.SqlClient;
 7 None.gif namespace  Count 
 8 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
10InBlock.gif    /// Global 的摘要说明。
11ExpandedSubBlockEnd.gif    /// </summary>

12InBlock.gif    public class Global : System.Web.HttpApplication
13ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
14ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
15InBlock.gif        /// 必需的设计器变量。
16ExpandedSubBlockEnd.gif        /// </summary>

17InBlock.gif        private System.ComponentModel.IContainer components = null;
18InBlock.gif
19InBlock.gif        public Global()
20ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
21InBlock.gif            InitializeComponent();
22ExpandedSubBlockEnd.gif        }
    
23InBlock.gif        
24InBlock.gif        protected void Application_Start(Object sender, EventArgs e)
25ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
26InBlock.gif            SqlConnection con=new SqlConnection("server=.;database=countpeople;uid=sa;pwd=xiaohui300;");
27InBlock.gif            con.Open();
28InBlock.gif            SqlCommand cmd=new SqlCommand("select * from countpeople",con);
29InBlock.gif            int count=Convert.ToInt32(cmd.ExecuteScalar());
30InBlock.gif            con.Close();
31InBlock.gif            Application["totol"]=count;
32InBlock.gif            Application["online"]=0;
33ExpandedSubBlockEnd.gif        }

34InBlock.gif 
35InBlock.gif        protected void Session_Start(Object sender, EventArgs e)
36ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
37InBlock.gif            Session.Timeout=1;
38InBlock.gif            Application.Lock();
39InBlock.gif            Application["totol"]=(int)Application["totol"]+1;
40InBlock.gif            Application["online"]=(int)Application["online"]+1;
41InBlock.gif            Application.UnLock();
42ExpandedSubBlockEnd.gif        }

43InBlock.gif
44InBlock.gif        protected void Application_BeginRequest(Object sender, EventArgs e)
45ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
46InBlock.gif
47ExpandedSubBlockEnd.gif        }

48InBlock.gif
49InBlock.gif        protected void Application_EndRequest(Object sender, EventArgs e)
50ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
51InBlock.gif
52ExpandedSubBlockEnd.gif        }

53InBlock.gif
54InBlock.gif        protected void Application_AuthenticateRequest(Object sender, EventArgs e)
55ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
56InBlock.gif
57ExpandedSubBlockEnd.gif        }

58InBlock.gif
59InBlock.gif        protected void Application_Error(Object sender, EventArgs e)
60ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
61InBlock.gif
62ExpandedSubBlockEnd.gif        }

63InBlock.gif
64InBlock.gif        protected void Session_End(Object sender, EventArgs e)
65ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
66InBlock.gif            Application.Lock();
67InBlock.gif            Application["online"]=(int)Application["online"]-1;
68InBlock.gif            Application.UnLock();
69ExpandedSubBlockEnd.gif        }

70InBlock.gif
71InBlock.gif        protected void Application_End(Object sender, EventArgs e)
72ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
73InBlock.gif            SqlConnection con=new SqlConnection("server=.;database=countpeople;uid=sa;pwd=xiaohui300;");
74InBlock.gif            con.Open();
75InBlock.gif            SqlCommand cmd=new SqlCommand("update countpeople set num="+Application["totol"].ToString(),con);
76InBlock.gif            cmd.ExecuteNonQuery();
77InBlock.gif            con.Close();
78ExpandedSubBlockEnd.gif        }

79InBlock.gif            
80ContractedSubBlock.gifExpandedSubBlockStart.gif        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
81ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
82InBlock.gif        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
83InBlock.gif        /// 此方法的内容。
84ExpandedSubBlockEnd.gif        /// </summary>

85InBlock.gif        private void InitializeComponent()
86ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{    
87InBlock.gif            this.components = new System.ComponentModel.Container();
88ExpandedSubBlockEnd.gif        }

89ExpandedSubBlockEnd.gif        #endregion

90ExpandedSubBlockEnd.gif    }

91ExpandedBlockEnd.gif}

92 None.gif
93 None.gif
此页面为Global.aspx全代码

转载于:https://www.cnblogs.com/icejd/archive/2006/04/02/364996.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值