zoukankan      html  css  js  c++  java
  • 客户端获取Cookie

    存入cookie代码:

     HttpCookie cookie = new HttpCookie("myuser");
                            cookie.Values.Add("UserLevel", model.UserLevel.ToString());
                            cookie.Values.Add("userLoginPhone", model.RegisterPhone);
                            cookie.Values.Add("UserId", model.UserId.ToString());
                            cookie.Values.Add("UserNickName", model.NickName);
                            cookie.Expires = DateTime.Now.AddDays(7);
                            Response.AppendCookie(cookie);

    调用代码:

    getCookie("UserId", "&")

    & 为截取分隔符

    js获取cookie代码:

    function getCookie(cookie_name, fhao) {
        var allcookies = document.cookie;
        var cookie_pos = allcookies.indexOf(cookie_name);   //索引的长度


        if (cookie_pos != -1) {

            cookie_pos += cookie_name.length + 1;
            var cookie_end = allcookies.indexOf(fhao, cookie_pos);

            if (cookie_end == -1) {
                cookie_end = allcookies.length;
            }

            var value = unescape(allcookies.substring(cookie_pos, cookie_end));
        }
        return value;
    }

  • 相关阅读:
    [APIO2014]序列分割
    [HNOI2008]玩具装箱TOY
    [ZJOI2007]时态同步
    [FJOI2014]最短路径树问题
    [IOI2011]Race
    [国家集训队]聪聪可可
    矩阵加速递推
    Codeforces Round #669 题意及思路
    Codeforces Round #670 题意及思路
    Codeforces Round #671 题意及思路
  • 原文地址:https://www.cnblogs.com/yinzhilei/p/5828851.html
Copyright © 2011-2022 走看看