写入Cookies
string userId = dt.Rows[0]["user_no"].ToString();
string userName = dt.Rows[0]["user_name"].ToString();
HttpCookie cookie = new HttpCookie("UserInFo");
//使用HttpUtility.UrlEncode 避免中文乱码
cookie.Values["userno"] = HttpUtility.UrlEncode(userId);
cookie.Values["username"] = HttpUtility.UrlEncode(userName);
Response.Cookies.Add(cookie);
读取Cookies
HttpCookie cookies = Request.Cookies["UserInfo"];
ViewBag.UserNo = HttpUtility.UrlDecode(cookies.Values["userno"]);
ViewBag.UserName = HttpUtility.UrlDecode(cookies.Values["username"];