我的cookie读写
前后臺(tái)必須一致,
后臺(tái):
public static void SetCookie(string cookieName, string value, int expiresDays)
{
??? var newCookie = new HttpCookie(cookieName);
??? newCookie.Value = value;
??? newCookie.Expires = DateTime.Now.AddDays(expiresDays);
??? newCookie.Path = "/";
??? System.Web.HttpContext.Current.Response.AppendCookie(newCookie);
}
public static string GetCookie(string cookieName)
{
??? if (System.Web.HttpContext.Current.Request.Cookies[cookieName] != null
??????? && !string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.Cookies[cookieName].Value))
??? {
??????? string value = System.Web.HttpContext.Current.Request.Cookies[cookieName].Value;
??????? return HttpUtility.UrlDecode(value);
??? }
??? return null;
}
?
調(diào)用者:
CookieHelper.SetCookie(ckIdName, "0", 7);
userId = CookieHelper.GetCookie(ckIdName)
前臺(tái):
$.cookie('productIds', "," + productId, { expires: 7, path: '/' });
必須一致才能進(jìn)行修改。
轉(zhuǎn)載于:https://www.cnblogs.com/luminji/p/4843555.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的我的cookie读写的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 搜索引擎排名不友好的五个地点-SEO
- 下一篇: 2.9-mysql主从配置-3