• 简单的 Helper 封装 -- CookieHelper


    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;
            }
        }
    }
    

      

  • 相关阅读:
    用图片来代替字符串
    下载网页时的 有gzip压缩的处理
    位置不固定验证码的识别
    CookieContainer 与 Session
    Thread Pool 备忘
    用 SGMLReader把子HTML 转 XML
    非asp.net控件实现回发 button
    ajax.net ??= 回车
    如何写需求分析
    jsp中地址
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/6484471.html
Copyright © 2020-2023  润新知