ASP.NET内蔵オブジェクトのApplicationオブジェクト

4063 ワード

2つのWebページを含む新しいWebサイトを作成します.コードは次のとおりです.
1、Index.aspxコード:
 
  
























   :








Index.aspx.csコード:
 
  
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Index : System.Web.UI.Page
{
string strInfo;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Application["Info"] = TextBox1.Text;
strInfo = Application["Info"].ToString();
if (TextBox1.Text == "admin" && TextBox2.Text == "admin")
{
Session["name"] = TextBox1.Text;
Response.Redirect("Default.aspx?Info=" + strInfo + "");//
}
}
}
2、Default.aspx :




















 





Default.aspx.cs :
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["name"].ToString();
/*
Application.Add("App1", "Value1");
Application.Add("App2", "Value2");
Application.Add("App3", "Value3");
Response.Write("Application ");
Response.Write("
");
for (int i = 0; i < Application.Count; i++)
{
Response.Write(" :" + Application.GetKey(i));
Response.Write(", :" + Application[i] + "

");
Response.Write("
");
}*/
}
protected void Button2_Click(object sender, EventArgs e)
{
Application["content"] = TextBox1.Text;
TextBox2.Text = TextBox2.Text + "
" + Label1.Text + " :" + Application["content"].ToString();
}
}