Microsoft KB Archive/262444

= PRB: Request.Cookies and Document.cookie Information Do Not Match =

Article ID: 262444

Article Last Modified on 10/23/2003

-

APPLIES TO


 * Microsoft Active Server Pages 4.0
 * Microsoft Internet Explorer 3.0
 * Microsoft Internet Explorer 3.01
 * Microsoft Internet Explorer 3.02
 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01

-



This article was previously published under Q262444



SYMPTOMS
When you use client-side code (document.cookie) to write cookies, the values written do not match the values that are returned by Request.Cookies in an Active Server Pages page. The most common behavior is that spaces are removed.

For example, if document.cookie is written using the code  document.cookie = &quot;MyCookie = Here is some text.&quot;  the value returned from Request.Cookies(&quot;MyCookie&quot;) is &quot;Hereissometext.&quot;.



CAUSE
Values written to document.cookie are not automatically encoded for HTTP. For example, a colon encoded for HTTP would be returned as &quot;%3A&quot;. Request.Cookies expects an encoded string. As a result, the unencoded string is interpreted as encoded, resulting in different values in document.cookie and Request.Cookies.



RESOLUTION
When your code writes a cookie to document.cookie, the code should use the JavaScript escape function to encode the value for the cookie. The following example writes a cookie called &quot;MyCookie&quot; and encodes the value. 

 document.cookie = &quot;MyCookie = &quot; & escape(&quot;Here is some text.&quot;)  Note: In order for you to use the JavaScript escape function from Microsoft Visual Basic Script (VBScript), you must reference the JavaScript scripting engine at least once in the HTML page (as seen in the example).



STATUS
This behavior is by design.

Keywords: kbscript kbprb KB262444

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.