zoukankan      html  css  js  c++  java
  • Cookie帮助类

    using System;
    using System.Web;
    
    namespace ConsoleApplication5
    {
        /// <summary>
        /// Cookie 助手
        /// </summary>
        public sealed class CookieHelper
        {
            /// <summary>
            /// 添加一个 Cookie
            /// </summary>
            /// <param name="name"></param>
            /// <param name="value"></param>
            public static void Add(string name, string value)
            {
                var cookie = new HttpCookie(name, value);
    
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
    
            /// <summary>
            /// 添加一个 Cookie
            /// </summary>
            /// <param name="name"></param>
            /// <param name="value"></param>
            /// <param name="expires">过期日期和时间</param>
            public static void Add(string name, string value, DateTime expires)
            {
                var cookie = new HttpCookie(name, value)
                {
                    Expires = expires
                };
    
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
    
            /// <summary>
            /// 获取 Cookie 值
            /// </summary>
            /// <param name="name"></param>
            /// <returns></returns>
            public static string Get(string name)
            {
                var cookie = HttpContext.Current.Request.Cookies[name];
    
                return cookie == null ? string.Empty : cookie.Value;
            }
        }
    }
  • 相关阅读:
    前端组件库
    lazyload隐藏元素不生效处理方法
    Javascript规范
    发送验证码
    flex
    css3转圈
    1.15考试总结
    [violet]蒲公英题解
    ubuntu和windows下的程序对拍
    [Poetize6] IncDec Sequence题解
  • 原文地址:https://www.cnblogs.com/HansZimmer/p/14339100.html
Copyright © 2011-2022 走看看