這裡主要采用cookIEs共享,覺得比較方便。
步驟1:[寫cookIEs]
//創建一個HttpCookIE對象
HttpCookie cookie = new HttpCookIE("uId");
//設定此cookIEs值
cookIE.Value = "uIdValue";
cookIE.Domain= "company.com";
//設定cookIE的生命周期,在這裡定義為一個小時
DateTime dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(0, 1, 0, 0);
cookIE.Expires = dtNow + tsMinute;
//加入此cookIE
Response.Cookies.Add(cookIE);
Response.Write(Request.Cookies["uId"].Value.ToString() + "CookIE創建完畢 <br > <hr > ");
步驟2:[讀cookIEs]
HttpCookie cookie = Request.CookIEs["uId"];
if (cookIE != null)
{
Response.Write(Request.CookIEs["uId"].Value.ToString();
}