Each cookie begins with a name-value pair. This pair is followed by zero or by more attribute-value pairs that are separated by semicolons. For one domain name, each cookie is limited to 4,096 bytes. This total can exist as one name-value pair of 4 kilobytes (KB) or as up to 20 name-value pairs that total 4 KB. If the computer does not have sufficient space to store the cookie, the cookie is discarded. It is not truncated. Applications should use as few cookies as possible and as small a cookie as possible. Additionally, applications should be able to handle the loss of a cookie.
If a Web application uses more than 19 custom cookies, ASP session state may be lost. Internet Explorer 4.0 and later versions allow a total of 20 cookies for each domain. Because ASPSessionID is a cookie, if you use 20 or more custom cookies, the browser is forced to discard the ASPSessionID cookie and lose the session.
To store more than 20 name-value pairs for a domain, you can create a cookie dictionary by concatenating several name-value pairs for each cookie up to the 4,096-byte limit for that cookie. Currently, to retrieve these values from client-side scripting, you must parse the cookies manually. However, the Active Server Pages
Request and
Response objects include built-in functionality to work with cookie dictionaries as dictionary objects. The following sample code demonstrates the use of cookie dictionary in an ASP page:
<%
Response.Cookies ("MyCookie")("a")="A"
Response.Cookies ("MyCookie")("b")="B"
Response.Cookies ("MyCookie")("c")="C"
Response.Cookies ("MyCookie")("d")="D"
Response.Cookies ("MyCookie")("e")="E"
Response.Cookies ("MyCookie")("f")="F"
Response.Cookies ("MyCookie")("g")="G"
Response.Cookies ("MyCookie")("h")="H"
Response.Cookies ("MyCookie")("i")="I"
Response.Cookies ("MyCookie")("j")="J"
Response.Cookies ("MyCookie")("k")="K"
Response.Cookies ("MyCookie")("l")="L"
Response.Cookies ("MyCookie")("a1")="A"
Response.Cookies ("MyCookie")("b1")="B"
Response.Cookies ("MyCookie")("c1")="C"
Response.Cookies ("MyCookie")("d1")="D"
Response.Cookies ("MyCookie")("e1")="E"
Response.Cookies ("MyCookie")("f1")="F"
Response.Cookies ("MyCookie")("g1")="G"
Response.Cookies ("MyCookie")("h1")="H"
Response.Cookies ("MyCookie")("i1")="I"
Response.Cookies ("MyCookie")("j1")="J"
Response.Cookies ("MyCookie")("k1")="K"
Response.Cookies ("MyCookie")("l1")="L"
Response.Cookies("MyCookie").Expires = "12/31/2001"
For Each strKey In Request.Cookies
Response.Write strKey & " = " & Request.Cookies(strKey) & "<BR><BR>"
If Request.Cookies(strKey).HasKeys Then
For Each strSubKey In Request.Cookies(strKey)
Response.Write "->" & strKey & "(" & strSubKey & ") = " & _
Request.Cookies(strKey)(strSubKey) & "<BR>"
Next
End If
Next
%>
Note In Internet Explorer 5.0 and later, you can use the
userData behavior to persist data across sessions. This behavior has a greater capacity than cookies.
If you use the
document.cookie property to retrieve the cookie on the client side, the
document.cookie property can retrieve only 4,096 bytes. This byte total can be one name-value pair of 4 KB, or it can be up to 20 name-value pairs that have a total size of 4 KB.
The
document.getcookie function calls the
CDocument::GetCookie method in Microsoft HTML.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
820536
Document.Cookie property returns an empty string