session (會話) 一系列有始有終的動作。資料私人性,會話結束,釋放資源,節省訪問器記憶體
易丟失,逾時時間很難確定
Session[“鍵名”]=值
cookie是網站儲存到用戶端的少量文本資料
優點:理論可以儲存8K的資料,可以自訂有效期間,不佔用伺服器磁碟空間,穩定性比較好
缺點:易丟失,安全性差
向Cookie寫入資料的C#代碼:
Response.Cookies[“userlgin”].value = “tom”;
讀取用戶端Cookie資料的C#代碼:
string uName = Request.Cookie[“userName”];
Application
cache
xml
檔案
資料庫
VieWState
//使用ViewState對象將值儲存起來,此對象的有效範圍為當前頁面都可以存取.最終儲存在用戶端。每次都會進行回送
//ViewState是StateBag類,可存放的資料類型有 int bool string 或數組 及其他的基礎資料型別 (Elementary Data Type),及arraylist,hashtable,
//或具有類型轉換器的類型,可以串列的類型
public string Text
{
get
{
if(ViewState["value"]==null)
{
return String.Empty;
}
return (string)ViewState["value"];
}
set
{
ViewState["value"]=value;
}
}
aspnetdb資料庫 profile個人化配置 成員資格和角色管理
Request.Tranfer()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using BLL;
using System.Data;
public partial class User_Question_Default : System.Web.UI.Page
{
public int num = 9;
private string name = "sa";
public string Name
{
get { return name; }
set { name = value; }
}
private string email = "@263";
public string Email
{
get { return email; }
set { email = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Context.Server.Transfer("Default2.aspx", true);
}
}
目標頁面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class User_Question_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
User_Question_Default ud = (User_Question_Default)Context.Handler; // 報錯了, 不影響運行,
Response.Write(ud.Name.ToString());
// Response.Write(Request.Form["TextBox1"].ToString()); //得到了一個類的對象 , 可以自由操作了
}
}