You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.4 KiB
C#

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace DSWeb.EntityDA
{
public class Cookies
{
public Cookies()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
//赋值
public bool setCookie(string strName, string strValue, int strDay)
{
try
{
HttpCookie Cookie = new HttpCookie(strName);
Cookie.Expires = DateTime.Now.AddDays(strDay);
Cookie.Value = strValue;
System.Web.HttpContext.Current.Request.Cookies.Add(Cookie);
return true;
}
catch
{
return false;
}
}
public bool setCookie(string strName, string strContent)
{
try
{
System.Web.HttpContext.Current.Response.Cookies[strName].Value = strContent.Trim();
System.Web.HttpContext.Current.Response.Cookies[strName].Expires = DateTime.MaxValue;
return true;
}
catch
{
return false;
}
}
//读取
public string getCookie(string strName)
{
try
{
HttpCookie Cookie = new HttpCookie(strName);
Cookie.Value = System.Web.HttpContext.Current.Request.Cookies[strName].Value.ToString();
if (Cookie != null)
{
return Cookie.Value.ToString();
}
else
{
return null;
}
}
catch (Exception)
{
return null;
}
}
//删除
public bool delCookie(string strName, string strValue, int strDay)
{
try
{
HttpCookie Cookie = new HttpCookie(strName);
Cookie.Expires = DateTime.Now.AddDays(-1);
System.Web.HttpContext.Current.Request.Cookies.Add(Cookie);
return true;
}
catch
{
return false;
}
}
}
}