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;
            }
        }
    }
  • 相关阅读:
    PHP自动加载(__autoload和spl_autoload_register)
    抽象工厂模式
    工厂方法模式
    简单工厂模式
    组合
    二叉树的层次遍历 II
    umask命令
    二叉树的所有路径
    CDN缓存的理解
    Js中RegExp对象
  • 原文地址:https://www.cnblogs.com/HansZimmer/p/14339100.html
Copyright © 2011-2022 走看看