c#cookie读取写入操作
程序员文章站
2023-03-25 19:04:09
public static void SetCookie(string cname, string value, int effective) { HttpCookie cookie = new HttpCookie(cname); cookie.Value = value; cookie.Expi... ......
public static void setcookie(string cname, string value, int effective) { httpcookie cookie = new httpcookie(cname); cookie.value = value; cookie.expires = datetime.now.adddays(effective); httpcontext.current.response.cookies.add(cookie); } public static object getcookie(string cname) { httpcookie cookie = httpcontext.current.request.cookies[cname]; return cookie; } public static void removecookie(string name) { httpcookie cookie = httpcontext.current.request.cookies[name]; if (cookie != null) { cookie.expires = datetime.now.adddays(-10); httpcontext.current.response.cookies.add(cookie); } }