Sobes.tech
Junior — Middle

Can cookies have size or expiration time limitations?

sobes.tech AI

Answer from AI

Yes, cookies have size and expiration time limitations:

  • Size: Browsers typically limit the size of a single cookie to about 4 KB (4096 bytes). If a cookie exceeds this size, it may not be saved or may be truncated.
  • Expiration: Cookies can be session-based (deleted when the browser is closed) or have a set lifetime through the Expires or Max-Age attribute. After the expiration time, the browser will automatically delete the cookie.

Example of setting a cookie with a lifetime in C#:

var cookie = new HttpCookie("user", "John")
{
    Expires = DateTime.Now.AddDays(7) // cookie will live for 7 days
};
Response.Cookies.Add(cookie);
Can cookies have size or expiration time limitations… - sobes.tech