首页 > 学院 > 开发设计 > 正文

CookieHelper.cs

2019-11-14 10:25:33
字体:
来源:转载
供稿:网友
using System;using System.Web;namespace Common{    public class CookieHelper    {        /// <summary>        /// 设置Cookie缓存        /// </summary>        /// <param name="sKey"></param>        /// <param name="sContent"></param>        /// <param name="dt"></param>        public static void CookieSet(string sKey,string sContent,DateTime dt)        {            HttpCookie myHttpCookie = new HttpCookie(sKey);            myHttpCookie.Value = sContent;            myHttpCookie.Expires = dt;            HttpContext.Current.Response.Cookies.Add(myHttpCookie);        }        /// <summary>          /// 清除指定Cookie          /// </summary>          /// <param name="sKey">cookiename</param>          public static void CookieClear(string sKey)        {            HttpCookie cookie = HttpContext.Current.Request.Cookies[sKey];            if (cookie != null)            {                cookie.Expires = DateTime.Now.AddYears(-3);                HttpContext.Current.Response.Cookies.Add(cookie);            }        }        /// <summary>          /// 获取指定Cookie值          /// </summary>          /// <param name="sKey">cookiename</param>          /// <returns></returns>          public static string CookieGet(string sKey)        {            HttpCookie cookie = HttpContext.Current.Request.Cookies[sKey];            string str = string.Empty;            if (cookie != null)            {                str = cookie.Value;            }            return str;        }    }}
上一篇:Storm入门学习随记

下一篇:洛谷 1372

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表