zoukankan      html  css  js  c++  java
  • 我的cookie读写

    前后台必须一致,

    后台:

    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;
    }

    调用者:

    CookieHelper.SetCookie(ckIdName, "0", 7);

    userId = CookieHelper.GetCookie(ckIdName)

    前台:

    $.cookie('productIds', "," + productId, { expires: 7, path: '/' });

    必须一致才能进行修改。

  • 相关阅读:
    oracle中文乱码问题
    并发登录查询
    AJAX 笔记
    jQuery笔记
    js BOM 笔记
    HTML DOM笔记
    JS函数笔记
    js笔记
    json笔记
    css3笔记
  • 原文地址:https://www.cnblogs.com/luminji/p/4843555.html
Copyright © 2011-2022 走看看