机制和Session(服务器端)很类似。
生命周期不一样,Session是该用户打开某个页面后的20min(默认值,可以改) ;Application是整个网站架起来的时候。
Session的销毁要么是人为销毁,要么是过期了;
传值页的前台:
<asp:TextBox ID="txtbValue" runat="server"></asp:TextBox>
<asp:Button ID="btnReturnValue" runat="server" OnClick="btnReturnValue_Click" Text="传递值" />
传值页的后台:
protected void btnReturnValue_Click(object sender, EventArgs e)
{
string name = txtbValue.Text;
Application["name"] = name;
Response.Redirect("Application.aspx");
}
接收页的后台:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if(Application["name"]!=null)
{
string newname = (string)Application["name"];
Response.Write(newname);
}
else Response.Write("Not Found!");
}
}