首页 > 代码库 > cookie和session的设置和读取

cookie和session的设置和读取

一、Cookie

设置 cookie

HttpCookie cookie = new HttpCookie(name);

cookie.Value = http://www.mamicode.com/user.UserID.ToString();

Response.Cookies.Add(cookie);

 

读取cookie

System.Web.HttpContext.Current.Request.Cookies[name].Value

 

 

二、Session

设置session
HttpContext.Current.Session.Add(name, value);


 根据session名获取session对象

HttpContext.Current.Session[name];