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.
DS7/DSWeb/EntityDA/cookies.cs

92 lines
2.4 KiB
C#

2 years ago
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)
{
2 years ago
2 years ago
try
{
2 years ago
HttpCookie Cookie = new HttpCookie(strName);
2 years ago
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;
}
}
}
}