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. 球的序列(formation.*)

      N个编号为1-n的球,每个球都有唯一的编号.这些球被排成两种序列,分别为A.B序列,现在需要重新寻找一个球的序列l,对于这个子序列l中任意的两个球,要求j,k(j<k),都要求满足lj在A中 ...

  2. G - Power Strings

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...

  3. Oracle-统计数据库表数据总数量

    create or replace procedure prc_table_count(p_flag out varchar2) AS TCOUNT number; SCOUNT number; CO ...

  4. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  5. hdu 1874 畅通project续

    最短路问题,尽管a!=b,可是同一条路測评数据会给你非常多个.因此在读入的时候要去最短的那条路存起来.........见了鬼了.坑爹 #include<iostream> #include ...

  6. Java集合类汇总记录--guava篇

    BiMap HashBiMap<K,V> 实现了两份哈希表数据结构(本类独立实现).分别负责两个方向的映射. EnumBiMap<K,V> 两个EnumMap对象分别负责两个方 ...

  7. jxl 导入导出Excel(有模板)

    1.导入 @Override public String importBusinessScope(File file, String unit_id) throws Exception { Workb ...

  8. Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈

    D. Vasya and Chess   Vasya decided to learn to play chess. Classic chess doesn't seem interesting to ...

  9. C Tricks(十六)—— 复制字符串

    while (*s++ = *t++); // target ⇒ source // 对于 C 语言而言,赋值运算符返回左值

  10. Flink之DataStreamAPI入门

    目录 Types Transformations Defining UDFs 本文API基于Flink 1.4 def main(args: Array[String]) { // 第一种会自动判断用 ...