标签:blog http ar os sp div on log ad
简单建立Cookie:
public enum CookieKey
{
UserLogin
}
public class CookieStorage
{
private const int LOGINEXPIRESTIME = 24 * 60;
public static object SetCookie(CookieKey key, string value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[key.ToString()];
if (cookie == null)
{
cookie = new HttpCookie(key.ToString());
string result = HttpUtility.UrlEncode(value);
cookie.Value = result;
cookie.Expires = System.DateTime.Now.AddMinutes(LOGINEXPIRESTIME);
HttpContext.Current.Response.Cookies.Add(cookie);
}
return value;
}
public static string GetCookie(CookieKey key)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[key.ToString()];
if (cookie != null)
{
string result = HttpUtility.UrlDecode(cookie.Value);
return result;
}
return string.Empty;
}
public static void ClearCookie(CookieKey key) {
HttpCookie cookie = HttpContext.Current.Request.Cookies[key.ToString()];
if (cookie != null)
{
cookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Current.Response.Cookies.Add(cookie);
}
}
}
标签:blog http ar os sp div on log ad
原文地址:http://www.cnblogs.com/xiguain/p/4075698.html