Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 262444 - Last Review: October 23, 2003 - Revision: 3.0
PRB: Request.Cookies and Document.cookie Information Do Not Match
This article was previously published under Q262444
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
<SCRIPT Language=vbscript>
document.cookie = "MyCookie = Here is some text."
</SCRIPT>
the value returned from Request.Cookies("MyCookie") is "Hereissometext.".
Values written to document.cookie are not automatically encoded for HTTP. For example, a colon (:) encoded for HTTP would be returned as "%3A". 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.
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 "MyCookie" and encodes the value.
<SCRIPT Language=javascript></SCRIPT>
<SCRIPT Language=vbscript>
document.cookie = "MyCookie = " & escape("Here is some text.")
</SCRIPT>
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).
This behavior is by design.
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
Retired KB Content DisclaimerThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate