// For session-only cookie, set expires to null
void SetCookie(string cookieName, string value, DateTime expires)
{
HttpCookie cookie = new HttpCookie(cookieName, value);
cookie.Expires = expires;
HttpContext.Response.Cookies.Remove(cookieName);
HttpContext.Response.SetCookie(cookie);
}
void RemoveCookie(string cookieName)
{
if (this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains(cookieName))
{
HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies[cookieName];
cookie.Expires = DateTime.Now.AddYears(-1);
this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
}
}
string GetCookieVal(string cookieName)
{
if (this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains(cookieName))
{
HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies[cookieName];
return cookie.Value;
}
return null;
}