Microsoft KB Archive/313282

= PRB: ASP.NET Does Not Encode Cookies in UrlEncode Format by Default =

Article ID: 313282

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q313282



SYMPTOMS
When you develop ASP.NET applications that share cookies between earlier versions of Microsoft Active Server Pages (ASP) and ASP.NET code, the data may not be encoded or unencoded as expected.



CAUSE
In earlier versions of Microsoft Active Server Pages (ASP), cookies are encoded in UrlEncode format when they are written, and cookies are unencoded when they are read. However, ASP.NET does not encode or unencode cookies in UrlEncode format by default. As a result, you may encounter unexpected behavior in ASP.NET applications.



Steps to Reproduce the Behavior
  In an earlier version of ASP, create a new ASP page, and then add the following code: <%@ Language=&quot;VBScript&quot;%> <%   Response.Cookies(&quot;MyCookie&quot;) = &quot;some value and other characters such as #, $, and so on&quot; Response.Cookies(&quot;MyCookie&quot;).Path = &quot;/&quot; Response.Write(Request.Cookies(&quot;MyCookie&quot;)) %>    Create a new .aspx page named CookieTest.aspx in the same project or application.  Add the following code to the .aspx page:  sub Page_Load Response.Write(&quot;Hello from CookieTest.aspx ... &quot;) Response.Write(Request.Cookies(&quot;MyCookie&quot;).Value + &quot; &quot;) end sub  Run the ASP page first. Take note of the output. Click Submit1 to browse to CookieTest.aspx. Notice that the output is encoded in UrlEncode format. This occurs because the ASP code from the previous page sets the cookie's data.</li>  To decode the data that is retrieved from the cookie, use the following syntax: Response.Write(Server.UrlDecode(Request.Cookies(&quot;MyCookie&quot;).Value)) </li></ol>

<div class="references_section">