效果:
(一)發送頁面
1、將在TextBox控件中輸入的字符串保存至Session對象中;
2、將在TextBox控件中輸入的數組保存至Session對象中;
3、將在日曆表中選中的對象保存至Session對象中;
4、用SessionAdd方法對重名的Key進行設置(目標位第一個控件),刷新頁面後第一個控件值被第四個覆蓋掉;
5、點擊超鏈接,跳轉頁面;
(二)讀取頁面(read頁面,所有代碼都寫在PageLoad事件當中)
1、讀取第一個文本框內容:
2、獲取數組:
3、獲取控件:
4、遍歷session:
Label1.Text=" ";
foreach(string _key in Session.Keys)
{Label1.Text+=("["+_key+"] @nbsp;"+Session[_key].GetType().ToString()+"<br/>")
5、獲取SessionID:
Label2.Text=Session.SessionID.ToString();
6、獲取Session的剩餘時間:
Label3.Text=Session.Timeout.ToString();
7、刪除全部session:
protected void Button1_Click(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect(Request.Url.LocalPath.ToString());//通過該方法,可以直接
}
8、刪除單個session:
protected void Button2_Click(object sender, EventArgs e)
{
Session.Remove("ss_txt");
Response.Redirect(Request.Url.LocalPath.ToString());
}