標籤:style blog color 使用 os 資料
想必這個肯定是大家使用中最常見的用法了,其操作與Application類似,作用於使用者個人,所以,過量的儲存會導致伺服器記憶體資源的耗盡。
優點:1.使用簡單,不僅能傳遞單一資料型別,還能傳遞對象。
2.資料量大小是不限制的。
缺點:1.在Session變數儲存大量的資料會消耗較多的伺服器資源。
2.容易丟失。
使用方法:1.在源頁面的代碼中建立你需要傳遞的名稱和值構造Session變數:Session["Name"]="Value(Or Object)";
2.在目的頁面的代碼使用Session變數取出傳遞的值。Result = Session["Nmae"]
注意:session不用時可以銷毀它,銷毀的方法是:清除一個:Session.Remove("session名");
清除所有:Session.Clear();
indextest.aspx後台頁面:
1 using System; 2 using System.Collections.Generic; 3 using System.Web; 4 using System.Web.UI; 5 using System.Web.UI.WebControls; 6 7 public partial class JajaWeixinQianduanWeb_WoYaoDingCan_indextest : System.Web.UI.Page 8 { 9 protected void Page_Load(object sender, EventArgs e)10 {11 12 }13 14 protected void btn_chuanzhi_Click(object sender, EventArgs e)15 {16 Session["name"] = this.txt_chuanzhi.Value;17 string s_url = "indextestlist.aspx";18 Response.Redirect(s_url);19 }20 }
indextestlist.aspx後台頁面:
1 using System; 2 using System.Collections.Generic; 3 using System.Web; 4 using System.Web.UI; 5 using System.Web.UI.WebControls; 6 7 public partial class JajaWeixinQianduanWeb_WoYaoDingCan_indextestlist : System.Web.UI.Page 8 { 9 protected void Page_Load(object sender, EventArgs e)10 { 11 string name;12 name = Session["name"].ToString();13 Response.Write(name);14 }15 }