MXS&Vincene ─╄OvЁ &0000007 ─╄OvЁ MXS&Vincene
MXS&Vincene ─╄OvЁ:今天很残酷,明天更残酷,后天很美好,但是绝大部分人是死在明天晚上,只有那些真正的英雄才能见到后天的太阳。
MXS&Vincene ─╄OvЁ:We're here to put a dent in the universe. Otherwise why else even be here?
正文>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public class CookieHelper
{
///<summary>
///清除指定Cookie
///</summary>
///<param name="cookiename">cookiename</param>
public static void ClearCookie(string cookiename)
{
HttpCookie cookie=HttpContext.Current.Request.Cookies[cookiename];
if(cookie!=null)
{
cookie.Expires=DateTime.Now.AddYears(-5);
HttpContext.Current.Response.Cookies.Add(cookie);
}
}
///<summary>
///获取指定Cookie值
///</summary>
///<param name="cookiename">cookiename</param>
///<return></return>
public static string GetCookieValue(string cookiename)
{
HttpCookie cookie=HttpContext.Current.Request.Cookies[cookiename];
string str=String.Empty;
if(cookie!=null)
{
str=cookie.Value;
}
return str;
}
///<summary>
///添加一个Cookie(24小时过期)
///</summary>
///<param name="cookiename">cookiename</param>
///<param name="cookievalue">cookievalue</param>
public static void SetCookie(string cookiename,string cookievalue)
{
SetCookie(cookiename,cookievalue,DateTime.Now.AddDays(1.0));
}
///<summary>
///添加一个Cookie
///</summary>
///<param name="cookiename">cookiename</param>
///<param name="cookievalue">cookievalue</param>
///<param name="expires">过期时间</param>
public static void SetCookie(string cookiename,string cookievalue,DateTime wxpiress)
{
HttpCookie cookie =new HttpCookie(cookiename)
{
Value=cookievalue,
Expires=expires
};
HttpContext.Current.Response.Cookie.Add(cookie);
}
}