zoukankan      html  css  js  c++  java
  • Cookie操作

    1、写cookie方法

        #region 登录时写入cookie
        public static void LoginCookieSave(string uid, string loginname, string pwd)
        {
            System.Web.HttpCookie logincookie = new System.Web.HttpCookie("userinfo");
            logincookie.Values.Add("uid", uid);
            logincookie.Values.Add("loginname", ICore.IChecking.Escape(loginname));
            logincookie.Values.Add("pwd", pwd);
            logincookie.Expires = DateTime.Now.AddMonths(12);
            logincookie.Domain = "domain.com";
            HttpContext.Current.Response.AppendCookie(logincookie);
        }
        #endregion

    2、读取cookie方法

        /// <summary>
        /// 获得Cookie的值
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCookieValue(string cookieName, string key)
        {
            HttpRequest request = HttpContext.Current.Request;
            if (request != null)
                return GetCookieValue(request.Cookies[cookieName], key);
            return "";
        }
    
    
        /// <summary>
        /// 获得Cookie的子键值
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetCookieValue(HttpCookie cookie, string key)
        {
            if (cookie != null)
            {
                if (!string.IsNullOrEmpty(key) && cookie.HasKeys)
                    return cookie.Values[key];
                else
                    return cookie.Value;
            }
            return "";
        }
  • 相关阅读:
    随笔1
    随笔
    shared_ptr<> reset
    c++模板库(简介)
    rockmongo用法
    随笔
    TEXT宏,TCHAR类型
    sprintf
    基于SOA的银行系统架构
    大纲6 信息化规划与管理
  • 原文地址:https://www.cnblogs.com/mingjia/p/5302936.html
Copyright © 2011-2022 走看看