c# 写入读取Cookie值
2014-03-25 14:14
369 查看
Code
/// <summary>
/// 写cookie值
/// </summary>
/// <param name="strName">名称</param>
/// <param name="strValue">值</param>
/// <param name="strValue">过期时间(分钟)</param>
public static void WriteCookie(string strName, string strValue, int expires)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
if (cookie == null)
{
cookie = new HttpCookie(strName);
}
cookie.Value = strValue;
cookie.Expires = DateTime.Now.AddMinutes(expires);
HttpContext.Current.Response.AppendCookie(cookie);
}
/// <summary>
/// 读cookie值
/// </summary>
/// <param name="strName">名称</param>
/// <returns>cookie值</returns>
public static string GetCookie(string strName)
{
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
{
return HttpContext.Current.Request.Cookies[strName].Value.ToString();
}
return "";
}
相关文章推荐
- C#制作源代码的帮助文档 chm帮助文档 C#类库帮助文档生成
- C#正则表达式引发的CPU跑高问题以及解决方法
- <C#任务导引教程>练习六
- C# 静态类的构造函数
- C#加解密
- C# Winform 开机自动启动
- C#对象序列化与反序列化
- C#——变量
- C#基础1——语法
- C#发送邮件(Gmail到qq邮箱和163邮箱)
- c#操作文件夹压缩到指定目录和解压到指定目录
- C#导入EXCEL数据
- VS2010快捷键
- C# 使用枚举数 避免使用switch语句
- C#如何获取其他程序ListView控件中的内容 含源码
- .Net(C#)访问X509证书加密的Webservice(一)--证书生成
- C# 中的委托和事件
- CSharp_delegate简单讲解;
- C# 随机数 Radom 循环生成同一的数字
- <C#任务导引教程>练习五