cookie에 관하여 (in asp.net terms)

cookier 쓰기

HttpCookie cookie = HttpContext.Current.Request.Cookies[settings.cookieName];
if (cookie == null)
{
    cookie = new HttpCookie(settings.cookieName, Guid.NewGuid().ToString());
    cookie.Expires = DateTime.Today.AddYears(1);
    Response.Cookies.Add(cookie);
}

In ASP.NET terms, a page receives a CookieCollection as a property of an HttpRequest object (usually Request.Cookies) and returns a CookieCollection of updates as a property of an HttpResponse object (usually Response.Cookies). from On The Care and Handling of Cookies

Set cookier

HttpCookie cookie = new HttpCookie(Settings.CookieName, encryptedTicket);
cookie.Expires = expiryDate;
BasePage.Response.Cookies.Add(cookie);

public static void RemoveCookie(Page page)
{
//Remove cookie if present
HttpCookie cookie = page.Request.Cookies[Settings.CookieName];
if (cookie != null)
{
HttpCookie expiredCookie = new HttpCookie(Settings.CookieName, “”);
expiredCookie.Expires = DateTime.Today.AddYears(-1);
page.Response.Cookies.Add(expiredCookie);
}
}

참고자료들

cookie에 관하여 (in asp.net terms)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s