下面代码将值写入 Cookie 并从 Cookie 中返回值。这有助于学习 Cookie 基本操作。
添加值到 Cookie 中
HttpCookie myCookie = new HttpCookie("myCookie");
myCookie.Values.Add("username", "UserNameToInsert");
myCookie.Values.Add("password", "PasswordToInsert");
从 Cookie 中获得值
HttpCookie cookie = Request.Cookies.Get("myCookie");
string UserName= cookie.Values["username"];
string Password= cookie.Values["password"];