Application和Session的例子
%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationTest.aspx.cs" Inherits="WebApplication1.ApplicationTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Application和Session的例子</title> </head> <body> <% //如果没有设置名为"ApplicationCount"的Application int applicationCount=1; int sessionCount=1; if(Application["ApplicationCount"]==null) { Application["ApplicationCount"]=1; } else//否则取出该Session,并且在当前值上加1 { applicationCount=(int)Application["ApplicationCount"]+1; Application["ApplicationCount"]=applicationCount; } //如果Session["SessionCount"]为空,即没有设置该名字的Session if(Session["SessionCount"]==null) { Session["SessionCount"]=1; } else { sessionCount=(int)Session["SessionCount"]+1; Session["SessionCount"]=sessionCount; } Response.Write("当前页面由Application记录到的被访问了"+applicationCount+"次<br/>"); Response.Write("当前页面由Session记录到的被访问了"+sessionCount+"次<br/>"); %>> </body> </html>