定义 CookieHelper 工具类缓存和获取Cookie信息
public class CookieHelper { //缓存Cookie信息 public static void Set(string strName, string strValue) { HttpCookie _cookie; try { _cookie = new HttpCookie(strName); _cookie.Value = strValue; _cookie.Expires = DateTime.Now.AddMonths(1); HttpContext.Current.Response.Cookies.Add(_cookie); } catch (Exception ex) { } } //获取Cookie信息 public static string Get(string strName) { try { HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; if (cookie != null) return cookie.Value.ToString(); else return string.Empty; } catch { return string.Empty; } } }
定义 CookieHelper 工具类缓存和获取Cookie信息
原文:https://www.cnblogs.com/wml-it/p/14758635.html