2020年10月14日 星期三

ASP.NET WebStatus 筆記

  •  Application   每個人儲存的為同一個

            protected void Button1_Click(object sender, EventArgs e)
            {
                  //存入
                  Application["mylab1015"] = TextBox1.Text;

            }

            protected void Button2_Click(object sender, EventArgs e)
            {
                  //讀取
                  Label1.Text = Application["mylab1015"].ToString();
            }



  • session   每個人儲存皆不同
            protected void btnSessionSave_Click(object sender, EventArgs e)
            {
                  Session["mySession1015"] = TextBox2.Text;
            }

            protected void btnSessionRead_Click(object sender, EventArgs e)
            {
                  if (Session["mySession1015"] == null)
                  {
                        Label2.Text = "沒有Session !!";
                  }
                  else
                  {
                        Label2.Text = Session["mySession1015"].ToString();
                  }
            }

  • cookie
            protected void btncookieSave_Click(object sender, EventArgs e)
            {
                  Response.Cookies["myCookie1015"].Value = TextBox3.Text;
                  Response.Cookies["myCookie1015"].Expires = DateTime.Now.AddDays(1);
            }

            protected void btncookieRead_Click(object sender, EventArgs e)
            {
                  if (Request.Cookies["myCookie1015"] == null)
                  {
                        Label3.Text = "沒有Cookie!!";
                  }
                  else
                  {
                        Label3.Text = Request.Cookies["myCookie1015"].Value;
                  }
                  
            }

  • catch


  • viewstate

沒有留言:

張貼留言