Skip to content

Instantly share code, notes, and snippets.

@theuntitled
Created April 27, 2016 08:32
Show Gist options
  • Select an option

  • Save theuntitled/9f9c327dc24b56c7b79142b8683f96c6 to your computer and use it in GitHub Desktop.

Select an option

Save theuntitled/9f9c327dc24b56c7b79142b8683f96c6 to your computer and use it in GitHub Desktop.
ASP.NET CookieJar Class
using System;
using System.Linq;
using System.Web;
namespace Project
{
public class CookieJar
{
public HttpRequest Request => return HttpContext.Current.Request;
public HttpResponse Response => return HttpContext.Current.Response;
public bool Has(string name)
{
return Request.Cookies.AllKeys.Contains(name);
}
public HttpCookie Get(string name)
{
if (!Has(name))
{
return null;
}
return Request.Cookies[name];
}
public void Add(HttpCookie cookie)
{
Response.AppendCookie(cookie);
}
public void Add(string name, string value)
{
Add(new HttpCookie(name, value));
}
public void Remove(string name)
{
if (Response.Cookies[name] != null)
{
Response.Cookies[name].Expires = DateTime.Now.AddDays(-1d);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment