在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
c#中cookies的存取操作 c#中cookies的存取 cookies的创建: 在客户端创建一个username的cookies,其值为gjy,有效期为1天. 方法1: Response.Cookies["username"].Value="zxf"; Response.Cookies["username"].Expires=DateTime.Now.AddDays(1); 方法2: System.Web.HttpCookie newcookie=new HttpCookie("username"); newcookie.Value="gjy"; newcookie.Expires=DateTime.Now.AddDays(1); Response.AppendCookie(newcookie); 创建带有子键的cookies: System.Web.HttpCookie newcookie=new HttpCookie("user"); newcookie.Values["username"]="zxf"; newcookie.Values["password"]="111"; newcookie.Expires=DateTime.Now.AddDays(1); Response.AppendCookie(newcookie); cookies的读取: 无子键读取: if(Request.Cookies["username"]!=null) { Response.Write(Server.HtmlEncode(Request.Cookies["username"].Value)); } 有子键读取: if(Request.Cookies["user"]!=null) { Response.Write(Server.HtmlEncode(Request.Cookies["user"]["username"].Value)); Response.Write(Server.HtmlEncode(Request.Cookies["user"]["password"].Value)); |
请发表评论