relaxlife.net .NET 操作Cookie的源代码



//*******************************************************************************
// OdbcHelper ODBC连接数据库方式
// [url]www.relaxlife.net[/url] 收藏
// QQ群:4341998
//*******************************************************************************
using System;
using System.Text;
using System.Web;

namespace Pub.Class
{
///
/// Cookie操作
///
public class Cookie
{
#region Set
///
/// 设置Cookies值
///
/// Cookies名称
/// Cookies名称对应的值
static public void Set(String InfoName, String InfoValue)
{
HttpContext.Current.Response.Cookies["Info"][InfoName] = InfoValue;
}
///
/// 设置Cookies值
///
/// Index
/// Cookies名称
/// Cookies名称对应的值
static public void Set(string Index, String InfoName, String InfoValue)
{
HttpContext.Current.Response.Cookies[Index][InfoName] = InfoValue;
}

///
/// 设置Cookies值
///
/// Cookies名称
/// Cookies名称对应的值
/// 有效期 天数
static public void Set(String InfoName, String InfoValue, int Dates)
{
HttpContext.Current.Response.Cookies["Info"].Expires = DateTime.Now.AddDays(Dates);
HttpContext.Current.Response.Cookies["Info"][InfoName] = InfoValue;
}
///
/// 设置Cookies值
///
/// Index
/// Cookies名称
/// Cookies名称对应的值
/// 有效期 天数
static public void Set(string Index, String InfoName, String InfoValue, int Dates)
{
HttpContext.Current.Response.Cookies[Index].Expires = DateTime.Now.AddDays(Dates);
HttpContext.Current.Response.Cookies[Index][InfoName] = InfoValue;
}
#endregion

#region Get
///
/// 取Cookies值
///
/// Cookies名称
/// Cookies名称对应的值
static public String Get(String InfoName)
{
string _value = "";
if (HttpContext.Current.Request.Cookies["Info"] != null)
if (HttpContext.Current.Request.Cookies["Info"][InfoName] != null)
_value = HttpContext.Current.Request.Cookies["Info"][InfoName].ToString();
return _value;
}
///
/// 取Cookies值
///
/// Index
/// Cookies名称
/// Cookies名称对应的值
static public String Get(string Index, String InfoName)
{
string _value = "";
if (HttpContext.Current.Request.Cookies[Index] != null)
if (HttpContext.Current.Request.Cookies[Index][InfoName] != null)
_value = HttpContext.Current.Request.Cookies[Index][InfoName].ToString();
return _value;
}
#endregion
}
}


附件附件:

您所在的用户组无法下载或查看附件

最后编辑cexo255 最后编辑于 2008-07-16 18:26:04
看帖回帖是每个网民应尽的义务...
喜欢的顶一下,楼主才会更有动力。