博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Cookie的设置
阅读量:5286 次
发布时间:2019-06-14

本文共 3044 字,大约阅读时间需要 10 分钟。

using System;using System.Web;using XTSoft.Com.DwCmsException;namespace XTSoft.Com.Common{    public sealed class CookieHelper    {        private CookieHelper()        {        }        ///         /// 获取一个数组形式的Cookies        ///         public static HttpCookie GetCookie(string name)        {            if (!string.IsNullOrEmpty(name))            {                return HttpContext.Current.Request.Cookies[name];            }            else            {                throw new DwException("键值为空!");            }        }        ///         /// 移除Cookies        ///         public static void RemoveCookie(string name)        {            RemoveCookie(GetCookie(name));        }        ///         /// 移除Cookies        ///         public static void RemoveCookie(HttpCookie cookie)        {            if (cookie != null)            {                cookie.Expires = new DateTime(1983, 1, 2);                Save(cookie);            }        }        ///         /// 保存Cookies        ///         public static void Save(HttpCookie cookie)        {            cookie.Domain = "";            HttpContext.Current.Response.AppendCookie(cookie);        }        ///         /// 获取一个新的Cookies        ///         public static HttpCookie GetNewCookie(string name)        {            return new HttpCookie(name);        }        ///         /// 取得指定名称的单值Cookie        ///         /// 
public static string GetCookieValue(string name) { HttpCookie cookie = GetCookie(name); if (cookie == null || cookie.Value == null) { return string.Empty; } else { return cookie.Value; } } /// /// 保存指定名称的单值Cookie /// ///
public static void SetCookie(string name, string value) { SetCookie(name, value, DateTime.Now); } /// /// 保存指定名称的单值Cookie /// ///
public static void SetCookie(string name, string value, DateTime expires) { HttpCookie cookie = GetCookie(name); if (cookie == null) { cookie = GetNewCookie(name); } cookie.Value = value; cookie.Expires = expires; Save(cookie); } /// /// 保存指定名称的单值Cookie /// ///
public static void SetCookie(string name, string value, string path, DateTime expires) { HttpCookie cookie = GetCookie(name); if (cookie == null) { cookie = GetNewCookie(name); } cookie.Path = path; cookie.Value = value; cookie.Expires = expires; Save(cookie); } /// /// 保存指定名称的单值Cookie /// ///
public static void SetCookie(string name, string value, string path) { SetCookie(name, value, path, DateTime.Now); } }}

 

转载于:https://www.cnblogs.com/d685600/p/3666143.html

你可能感兴趣的文章
第二百三十八节,Bootstrap输入框和导航组件
查看>>
js重写原型对象
查看>>
$this的用法
查看>>
linux如何安装java环境
查看>>
Android中gravity的含义
查看>>
求大神给解决下,向已有的xml文件写入数据,但不覆盖文件存在的内容
查看>>
深入理解java嵌套类和内部类
查看>>
Linux守护进程的编程实现
查看>>
C语言指针的初始化和赋值
查看>>
JavaScript 输出
查看>>
python 函数(2)
查看>>
Python学习笔记1:python简介、输入输出、循环条件
查看>>
python学习笔记5:装饰器
查看>>
Android 开发环境配置
查看>>
skiing
查看>>
wxwidgets demo
查看>>
dubbo 实战总结
查看>>
bzoj1230 [Usaco2008 Nov]lites 开关灯
查看>>
Modulation of Lipid Metabolism by Celastrol (文献分享一组-赵倩倩)
查看>>
HDU 1044 Collect More Jewels(BFS+DFS)
查看>>