Fórmulas e Cenas

Object Reference Not Set to Instance of an Object

  Home  |   Contact  |   Syndication    |   Login
  40 Posts | 0 Stories | 7 Comments | 0 Trackbacks

News

Archives

Post Categories

Links

So, yesterday I was asked to create a cookie to store some information that could be used latter on.

I have never worked with cookies before and it was a nice surprise when google told me it was quite simple :)

To create a Cookie:

HttpCookie bolacha = new HttpCookie("CookieName");
bolacha.Values.Add("Key1",Value1);
bolacha.Values.Add("Key2",Value2);
bolacha.Expires = DateTime.Now + new TimeSpan(0, 1, 0, 0); // Set to expire in 1 day
Response.Cookies.Add(bolacha);

To Read a Cookie:

HttpCookie bolacha = Request.Cookies["CookieName"];
if (bolacha != null)
{
       string value=bolacha.Values["Key1"]:
}


I think MS could not had made it any easier :)
posted on Friday, January 30, 2009 10:46 AM