zoukankan      html  css  js  c++  java
  • CookieHelper

    using System.Web:

     /// <summary>
        /// CookieHelper
        /// </summary>
        public static class CookieHelper
        {
            /// <summary>
            /// Cookies赋值
            /// </summary>
            /// <param name="strName">主键</param>
            /// <param name="strValue">键值</param>
            /// <param name="strDay">有效分钟</param>
            /// <returns></returns>
            public static bool SetCookie(string strCookieName, string strCookieValue, int intMin)
            {
                try
                {
                    HttpCookie cookie = new HttpCookie(strCookieName); //创建一个cookie对象  
                    cookie.Value = strCookieValue; //设置cookie的值  
                    cookie.Expires = DateTime.Now.AddMinutes(intMin); //或cookie.Expires.AddDays(intDay);设置cookie的有效期  
                    HttpContext.Current.Response.Cookies.Add(cookie); //将cookie添加到cookies中  
                    return true;
                }
                catch
                {
                    return false;
                }
            }
    
            /// <summary>
            /// 读取Cookies
            /// </summary>
            /// <param name="strName">主键</param>
            /// <returns></returns>
    
            public static string GetCookie(string strCookieName)
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[strCookieName];//获取cookie  
                if (cookie != null)
                {
                    return cookie.Value; //返回cookie的值  
                }
                else
                {
                    return null;
                }
            }
    
            /// <summary>
            /// 删除Cookies
            /// </summary>
            /// <param name="strName">主键</param>
            /// <returns></returns>
            public static bool delCookie(string strName)
            {
                try
                {
                    HttpCookie Cookie = new HttpCookie(strName);
                    //Cookie.Domain = ".xxx.com";//当要跨域名访问的时候,给cookie指定域名即可,格式为.xxx.com
                    Cookie.Expires = DateTime.Now.AddMinutes(-1);
                    System.Web.HttpContext.Current.Response.Cookies.Add(Cookie);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
  • 相关阅读:
    vip视频播放
    一行Python代码画心型
    使用赫夫曼编码压缩数据
    动态规划与贪婪算法学习笔记
    boost 编写finger服务
    磁盘保护原理简介
    知乎上的一道题目 如何判断某个二进制数如是否存在两位1中间有包含0的情况?
    <Linux多线程服务端编程>学习记录
    Debian8 下面 muduo库编译与使用
    无盘工作站原理分析
  • 原文地址:https://www.cnblogs.com/MrZheng/p/8966149.html
Copyright © 2011-2022 走看看