• 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;
                }
            }
        }
  • 相关阅读:
    JS Ajax跨域访问
    CentOS 6.8 Java 环境搭建
    vue+vant ui+高德地图的选址组件
    vue和element全局loading
    axios简单的二次封装
    vuex的简单教程
    vue 使用 element ui动态添加表单
    Promise对象和async函数
    css不定高图文垂直居中的三种方法
    js点击复制文本
  • 原文地址:https://www.cnblogs.com/MrZheng/p/8966149.html
Copyright © 2020-2023  润新知