【.NET】Cookie操作类
public static class CookiesHelper
{
/// <summary>
/// Cookies赋值
/// </summary>
/// <param name="strName">主键</param>
/// <param name="strValue">键值</param>
/// <param name="strDay">有效天数</param>
/// <returns></returns>
public static bool SetCookie(string strName, string strValue, int strDay)
{
try
{
HttpCookie Cookie = System.Web.HttpContext.Current.Request.Cookies[strName];
if (Cookie == null)
{
Cookie = new HttpCookie(strName);
}
Cookie.Expires = DateTime.Now.AddDays(strDay);
Cookie.Value = strValue;
System.Web.HttpContext.Current.Response.Cookies.Add(Cookie);
return true;
}
catch
{
return false;
}
} /// <summary>
/// 读取Cookies
/// </summary>
/// <param name="strName">主键</param>
/// <returns></returns> public static string GetCookie(string strName)
{
HttpCookie Cookie = System.Web.HttpContext.Current.Request.Cookies[strName];
if (Cookie != null)
{
return Cookie.Value.ToString();
}
else
{
return null;
}
} /// <summary>
/// 删除Cookies
/// </summary>
/// <param name="strName">主键</param>
/// <returns></returns>
public static bool DelCookie(string strName)
{
try
{
HttpCookie Cookie = System.Web.HttpContext.Current.Request.Cookies[strName];// new HttpCookie(strName);
Cookie.Expires = DateTime.Now.AddDays(-);
System.Web.HttpContext.Current.Response.Cookies.Add(Cookie);
return true;
}
catch
{
return false;
}
}
}
【.NET】Cookie操作类的更多相关文章
- Cookie操作类、 包括创建、读取、修改、获取、销毁cookie
Cookie操作类. 包括创建.读取.修改.获取.销毁cookie import java.util.Hashtable; import java.util.Iterator; import java ...
- Cookie操作类 实现记住用户名和密码的功能
import java.util.Hashtable;import java.util.Iterator;import java.util.Set;import javax.servlet.http. ...
- Cookie操作类、压缩、序列化
1.cookie类 CartCookie.cs using System; using System.Data; using System.Configuration; using System.We ...
- C#Cookie操作类,删除Cookie,给Cookie赋值
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security ...
- C#语法糖之Cookies操作类 asp.net
用法: //声名一个数据集合 var listString = new List<string>() { "a", "b", "c&quo ...
- Http下的各种操作类.WebApi系列~通过HttpClient来调用Web Api接口
1.WebApi系列~通过HttpClient来调用Web Api接口 http://www.cnblogs.com/lori/p/4045413.html HttpClient使用详解(java版本 ...
- 【PHPsocket编程专题(实战篇②)】兼容 Curl/Socket/Stream 的 HTTP 操作类[转]
<?php /************************************************************ * 描述:HTTP操作类 * 作者:heiyeluren ...
- Cookie 操作工具类
import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet ...
- session操作类
using System;using System.Web; /// <summary> ///session操作类 /// </summary> public class a ...
随机推荐
- LeetCode Online Judge 1. Two Sum
刷个题,击败0.17%... Given an array of integers, return indices of the two numbers such that they add up t ...
- IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习保护API
IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习之保护API. 使用IdentityServer4 来实现使用客户端凭据保护ASP.N ...
- 学习Redis你必须了解的数据结构——双向链表(JavaScript实现)
本文版权归博客园和作者吴双本人共同所有,转载和爬虫请注明原文链接 http://www.cnblogs.com/tdws/ 下午分享了JavaScript实现单向链表,晚上就来补充下双向链表吧.对链表 ...
- js正则表达式校验非负浮点数:^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 搭建公司内部的NuGet Server
随着公司业务慢慢的拓展,项目便会越来越来多,很多项目会依赖其他项目DLL,比如一些底层的技术框架DLL引用,还有各业务系统的也有可能会有引用的可能. 项目多,交叉引用多,如果要是有一个DLL更新,那就 ...
- Xcode7.1环境下上架iOS App到AppStore 流程① (Part 一)
前言部分 之前App要上架遇到些问题到网上搜上架教程发现都是一些老的版本的教程 ,目前iTunesConnect 都已经迭代好几个版本了和之前的 界面风格还是有很大的差别的,后面自己折腾了好久才终于把 ...
- Linux下Weblogic创建域方法和步骤
Weblogic 创建域 以weblogic帐号登录(与创建域目录相对应账户) cd /home/weblogic/bea/weblogic92/common/bin 执行./config.sh进入配 ...
- ActiveMQ 简单搭建
========== ActiveMQ ============== JMS : topic : 一对多: 发布订阅: 不保证数据是否被接受: 不存储topic信息: Queue : 一对一: 点对点 ...
- ASP.NET MVC4入门到精通系列目录汇总
序言 最近公司在招.NET程序员,我发现好多来公司面试的.NET程序员居然都没有 ASP.NET MVC项目经验,其中包括一些工作4.5年了,甚至8年10年的,许多人给我的感觉是:工作了4.5年,We ...
- Java面试题整理二(侧重SSH框架)
1.持久化对象的状态都有哪些? 答:瞬时对象(Transient Objects):使用new 操作符初始化的对象不是立刻就持久的.它们的状态是瞬时的,也就是说它们没有任何跟数据库表相关联的行为,只要 ...