using System;
using System.Collections.Generic;
using System.Text;
using System.Web; namespace Maticsoft.DBUtility
{
public class CookieHelper
{
/// <summary>
/// 设置cookie
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
/// <param name="day"></param>
/// <returns></returns>
public static bool setCookie(string name, string value, int day)
{
try
{
HttpCookie cookie = new HttpCookie(name);
cookie.Expires = DateTime.Now.AddDays(day);
cookie.Value = value;
HttpContext.Current.Response.Cookies.Add(cookie);
return true;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// 获取cookie
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string getCookie(string name)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
if (cookie != null)
{
return cookie.Value.ToString();
}
return null;
}
/// <summary>
/// 删除cookie
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool delCookie(string name)
{
try
{
HttpCookie cookie = new HttpCookie(name);
cookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(cookie);
return true;
}
catch (Exception)
{
return false;
}
}
}
}

  

c# cookie帮助类的更多相关文章

  1. java cookie 工具类

    package com.xxx.xxx.xxx.xxx; import java.net.URLDecoder; import java.net.URLEncoder; import javax.se ...

  2. cookie工具类,解决servlet3.0以前不能添加httpOnly属性的问题

    最近在解决XSS注入的问题,由于使用的servlet版本是2.5,不支持httpOnly的属性,故做了个工具类来实现cookie的httpOnly的功能.全类如下: /** * cookie工具类,解 ...

  3. Cookie工具类

    import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet ...

  4. Cookie工具类 - CookieUtil.java

    Cookie工具类,提供Cookie的创建.获取.删除方法. 源码如下:(点击下载 -CookieUtil.java ) import javax.servlet.http.Cookie; impor ...

  5. Cookie帮助类

    using System; using System.Collections.Generic; using System.Text; using System.Web; namespace AIMSC ...

  6. Cookie 操作工具类

    import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet ...

  7. Java Cookie工具类

    1.Cookie跨域 Cookie不能跨顶级域名访问,但是二级域名可以共享Cookie,所以要实现跨域,有一定的局限性. 2.代码 package com.DingYu.Cookie; import ...

  8. 180425、cookie工具类

    package com.thinkgem.jeesite.common.utils; import java.io.UnsupportedEncodingException; import java. ...

  9. Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie

    Java Cookie工具类,Java CookieUtils 工具类,Java如何增加Cookie >>>>>>>>>>>>& ...

  10. 170403、java 版cookie操作工具类

    package com.rick.utils; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; imp ...

随机推荐

  1. 洛谷 P1843 奶牛晒衣服

    题目背景 熊大妈决定给每个牛宝宝都穿上可爱的婴儿装 . 于是 , 为牛宝宝洗晒衣服就成了很不爽的事情. 题目描述 熊大妈请你帮助完成这个重任 . 洗完衣服后 , 你就要弄干衣服 . 衣服在自然条件下用 ...

  2. noip模拟赛 楼

    分析:题目可以转化为对于一个数,对它进行x次减法操作,n-x次加法操作,使他变成最小的非负整数.因为每减一次数就会减小,次数是一定的,所以可以二分x,就可以了. #include <cstdio ...

  3. poj 1724 最短路+优先队列(两个约束条件)

    /*两个约束条件求最短路,用优先队列*/ #include<stdio.h> #include<string.h> #include<queue> using na ...

  4. nyoj_171_聪明的kk_201402281518

    聪明的kk时间限制:1000 ms  |  内存限制:65535 KB 难度:3描述 聪明的“KK”非洲某国展馆的设计灵感源于富有传奇色彩的沙漠中陡然起伏的沙丘,体现出本国不断变换和绚丽多彩的自然风光 ...

  5. 233 Matrix 矩阵快速幂

    In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...

  6. Mac下使用OpenMP

    Mac下使用OpenMP,修改Build Options 下面的compiler for c/c++/objective-C 为 LLVM GCC 4.2 - Language 则可以找到Enable ...

  7. [RxJS] exhaustMap vs switchMap vs concatMap

    exhaustMap: It drop the outter observable, just return the inner observable, and it waits until prev ...

  8. ios最新设置状态栏字体颜色总结

    状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarStyleLightContent 一.在info.plist中,将View contro ...

  9. linux下启动jekins报错

    进入默认安装目录,执行java -jar jekins.war 启动使用端口号: java -jar jenkins.war --httpPort=8085,即启动完成 这个有个弊端,关闭后下次还得这 ...

  10. java 将byte[]转为各种进制的字符串

    public void test() { byte[] bytes = new byte[10000000]; for (int i = 0; i < 10000000; i++) { if ( ...