using System.Web:

 /// <summary>
/// CookieHelper
/// </summary>
public static class CookieHelper
{
/// <summary>
/// Cookies赋值
/// </summary>
/// <param name="strName">主键</param>
/// <param name="strValue">键值</param>
/// <param name="strDay">有效分钟</param>
/// <returns></returns>
public static bool SetCookie(string strCookieName, string strCookieValue, int intMin)
{
try
{
HttpCookie cookie = new HttpCookie(strCookieName); //创建一个cookie对象
cookie.Value = strCookieValue; //设置cookie的值
cookie.Expires = DateTime.Now.AddMinutes(intMin); //或cookie.Expires.AddDays(intDay);设置cookie的有效期
HttpContext.Current.Response.Cookies.Add(cookie); //将cookie添加到cookies中
return true;
}
catch
{
return false;
}
} /// <summary>
/// 读取Cookies
/// </summary>
/// <param name="strName">主键</param>
/// <returns></returns> public static string GetCookie(string strCookieName)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[strCookieName];//获取cookie
if (cookie != null)
{
return cookie.Value; //返回cookie的值
}
else
{
return null;
}
} /// <summary>
/// 删除Cookies
/// </summary>
/// <param name="strName">主键</param>
/// <returns></returns>
public static bool delCookie(string strName)
{
try
{
HttpCookie Cookie = new HttpCookie(strName);
//Cookie.Domain = ".xxx.com";//当要跨域名访问的时候,给cookie指定域名即可,格式为.xxx.com
Cookie.Expires = DateTime.Now.AddMinutes(-);
System.Web.HttpContext.Current.Response.Cookies.Add(Cookie);
return true;
}
catch
{
return false;
}
}
}

CookieHelper的更多相关文章

  1. [C#] 简单的 Helper 封装 -- CookieHelper

    using System; using System.Web; namespace ConsoleApplication5 { /// <summary> /// Cookie 助手 // ...

  2. Javascript操作Cookie的脚本 — CookieHelper

    var HttpCookie = function(name, value, expires, path, domain) { if (name) this.Name = name; if (valu ...

  3. CookieHelper JS封装Cookie 存取方法

    微信的一些页面会去获取授权,然后在回调到页面,但是这样的话通过url传递的参数有可能丢失掉,我采用存储cookie的方式来传值 建一个CookieHelper.js文件 function Cookie ...

  4. C# CookieHelper

    using System; using System.Web; using System.Collections.Specialized; namespace Utils { /// <summ ...

  5. 简单的 Helper 封装 -- CookieHelper

    using System; using System.Web; namespace ConsoleApplication5 { /// <summary> /// Cookie 助手 // ...

  6. .net core2.1 CookieHelper

    /// <summary> /// ** 描述:Cookie for .net core2.1 /// ** 创始时间:2018-11-19 /// ** 修改时间:- /// ** 作者 ...

  7. WebHelper-SessionHelper、CookieHelper、CacheHelper、Tree

    ylbtech-Unitity: cs-WebHelper-SessionHelper.CookieHelper.CacheHelper.Tree SessionHelper.cs CookieHel ...

  8. MVC中Cookie的用法(二)---CookieHelper

    public class CookieHelper { /// <summary> /// 1.1添加Cookie /// </summary> /// <param n ...

  9. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

随机推荐

  1. map里面的set方法

    let a=[1,2,3,4,1,2,3,4,1,4];let b= new Set(a);console.log(b) 还有add方法介绍下: let a=new Set();let b=[1,1, ...

  2. Cardinal and Ordinal Numbers

    Cardinal Numbers Table of Cardinal Numbers Cardinal numbers from 1 through 1,000,000 1 one 11 eleven ...

  3. CentOS中service命令与/etc/init.d的关系以及centos7的变化

    缘由 由于个人经常在ubuntu和centos 系统中切换,习惯了以前的 ubuntu中 通过 /etc/init.d/xxx 进行软件服务控制.后来发现centos7中换了服务的控制方式:servi ...

  4. I2C驱动框架 (kernel-3.4.2)

    先用韦老师的图: 注:  新版本内核的i2c驱动框架采用了    i2c_client -------> i2c_bus_type  <-------- i2c_driver   框架 如 ...

  5. nvm 安装使用

    事先说明-------先安装nvm,再安装nodejs [nvm参考安装地址] nvm install 6.9.4 # 安装nodejs6.9.4版本 nvm use 6.9.4 # 使用nodejs ...

  6. 【托业】【跨栏阅读】错题集-REVIEW1

    05 06 REVIEW 1

  7. PHP 二位数组按照下标排序

    1.排序得内容 array(6) { [0] => array(12) { [0] => string(3) "160" [1] => string(2) &qu ...

  8. 身份证运算符 is 和 is not(检查两个数据在内存当中是否是同一个值) | 逻辑运算符 and or not | 数据类型的判断 isinstance

    # ###身份证运算符 is 和 is not(检查两个数据在内存当中是否是同一个值) var1 = 6 var2 = 6 print(id(var1),id(var2)) var1 = " ...

  9. Android签名文件转化为pk8和pem来对apk重签名

    当我们需要修改已经打包好的apk中的某个文件时,比如改下图标,我们势必要采用反编译apk,改文件,重编译apk,重签名才行,参考:https://www.cnblogs.com/zndxall/p/9 ...

  10. Python sys.argv[]用法

    sys.argv,其实就是一个list,它是sys模块下的一个全局变量,第一个元素是模块名.后面是依次传入的参数. 比如可以这样传入 pyton temp.py a b c d,一共传入a.b.c.d ...