using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Application["App1"] = "value1"; Application["App2"] = "value2"; Application["App3"] = "value3"; int N; for (N = 0; N < Application.Count; N++) { Response.Write("变量名:" + Application.GetKey(N)); Response.Write("变量值:" + Application.Get(N) + "</br>"); } Application.Lock(); Application["App1"] = "zhang"; Application["App2"] = "wang"; Application["App3"] = "li"; Application.UnLock(); //修改后的变量 Response.Write("修改后的变量值</br>"); for (N = 0; N < Application.Count; N++) { Response.Write("变量名:" + Application.GetKey(N)); Response.Write("变量值:" + Application.Get(N) + "</br>"); } } protected void Button1_Click(object sender, EventArgs e) { Application.Lock(); Application["PageClick"] = (int)Application["PageClick"] + 1; Application["UserVisit"] = (int)Application["UserVisit"] + 1; Application.UnLock(); Response.Write(string.Format("页面单击数:{0}<br/>", Application["PageClick"])); Response.Write(string.Format("用户访问数:{0}<br/>", Application["UserVisit"])); } }
<%@ Application Language="C#" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { //在应用程序启动时运行的代码 Application["count"] = 0; } void Application_End(object sender, EventArgs e) { //在应用程序关闭时运行的代码 } void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 } void Session_Start(object sender, EventArgs e) { //在新会话启动时运行的代码 Application.Lock(); Application["count"] = (int)Application["count"] + 1; Application.UnLock(); } void Session_End(object sender, EventArgs e) { //在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 // InProc 时,才会引发 Session_End 事件。如果会话模式 //设置为 StateServer 或 SQLServer,则不会引发该事件。 Application.Lock(); Application["count"] = (int)Application["count"] -1; Application.UnLock(); } </script>
时间: 2024-11-10 02:58:53