Skip to main content

How To Use Cookie in ASP.NET

How to Create a Cookie ? HttpCookie objCookie = new HttpCookie(cookiename); Response.Cookies.Clear(); Response.Cookies.Add(objCookie); objCookie.Values.Add(cookiename,cookievalue); DateTime dtExpiry = DateTime.Now.AddDays(iDaysToExpire); Response.Cookies[cookiename].Expires =dtExpiry; How to Read Cookie ? string value= Request.Cookies[cookiename].Value; How to Delete a Cookie? Response.Cookies[cookiename].Expires = DateTime.Now.AddYears(-30); Checking for Cookie in ASP.NET? if (Request.Cookies[cookiename] == null) TextBox2.Text = "No cookie found"; else TextBox2 .Text = Request.Cookies[cookiename].Value;

Comments

Popular posts from this blog