{"id":151,"date":"2015-04-21T22:50:07","date_gmt":"2015-04-21T22:50:07","guid":{"rendered":"http:\/\/www.danieledavi.com\/blog\/?p=151"},"modified":"2015-04-22T09:49:05","modified_gmt":"2015-04-22T09:49:05","slug":"write-special-characters-in-cookies-with-classic-asp","status":"publish","type":"post","link":"https:\/\/www.danieledavi.com\/blog\/2015\/04\/write-special-characters-in-cookies-with-classic-asp\/","title":{"rendered":"Write special characters in cookies with classic ASP"},"content":{"rendered":"<p>The following code line<\/p>\n<pre>Response.Cookies(\"test\")= \"__cf_mob_redir\"<\/pre>\n<p>will produce a cookie named &#8220;test&#8221; whith value &#8220;%5F%5Fcf%5Fmob%5Fredir&#8221;<\/p>\n<p>Perhaps is not what we wanted.<\/p>\n<p>Even if we could decode the result when reading the cookie that string is very ugly. Could also happen that our responsibility is limited to write the right value and someone else will take care of reading the expected value.<\/p>\n<p>What to do?<\/p>\n<p>First, is useful to know that encoding the special character _ (underscore) in ASP as <span style=\"color: #ff0000;\">chr(95)<\/span> or as HTML entity <span style=\"color: #ff0000;\">&amp;#95<\/span> will not solve the situation. The same for any other special characters.<\/p>\n<p>Second, is better to underline that not always we want to send an html body as response, since sometimes we want just send headers. In case we want to send a body the following lines are a nice style exercise to write javascript through ASP code.<\/p>\n<pre class=\"default prettyprint prettyprinted\" style=\"color: #393318;\"><code><span class=\"typ\" style=\"color: #2b91af;\">Response<\/span><span class=\"pun\" style=\"color: #000000;\">.<\/span><span class=\"typ\" style=\"color: #2b91af;\">Write<\/span><span class=\"pun\" style=\"color: #000000;\">(<\/span><span class=\"str\" style=\"color: #800000;\">\"&lt;script type=\"<\/span><span class=\"pun\" style=\"color: #000000;\">&amp;<\/span><span class=\"pln\" style=\"color: #000000;\">chr<\/span><span class=\"pun\" style=\"color: #000000;\">(<\/span><span class=\"lit\" style=\"color: #800000;\">34<\/span><span class=\"pun\" style=\"color: #000000;\">)&amp;<\/span><span class=\"str\" style=\"color: #800000;\">\"text\/javascript\"<\/span><span class=\"pun\" style=\"color: #000000;\">&amp;<\/span><span class=\"pln\" style=\"color: #000000;\">chr<\/span><span class=\"pun\" style=\"color: #000000;\">(<\/span><span class=\"lit\" style=\"color: #800000;\">34<\/span><span class=\"pun\" style=\"color: #000000;\">)&amp;<\/span><span class=\"str\" style=\"color: #800000;\">\"&gt;\"<\/span><span class=\"pun\" style=\"color: #000000;\">)<\/span><span class=\"pln\" style=\"color: #000000;\">\r\njjj1 <\/span><span class=\"pun\" style=\"color: #000000;\">=<\/span><span class=\"str\" style=\"color: #800000;\">\"document.cookie=\"<\/span><span class=\"pun\" style=\"color: #000000;\">&amp;<\/span><span class=\"pln\" style=\"color: #000000;\">chr<\/span><span class=\"pun\" style=\"color: #000000;\">(<\/span><span class=\"lit\" style=\"color: #800000;\">34<\/span><span class=\"pun\" style=\"color: #000000;\">)&amp;<\/span><span class=\"str\" style=\"color: #800000;\">\"YOURcookiename=__cf_mob_redir\"<\/span><span class=\"pun\" style=\"color: #000000;\">&amp;<\/span><span class=\"pln\" style=\"color: #000000;\">chr<\/span><span class=\"pun\" style=\"color: #000000;\">(<\/span><span class=\"lit\" style=\"color: #800000;\">34<\/span><span class=\"pun\" style=\"color: #000000;\">)\r\n<\/span><span class=\"typ\" style=\"color: #2b91af;\">Response<\/span><span class=\"pun\" style=\"color: #000000;\">.<\/span><span class=\"typ\" style=\"color: #2b91af;\">Write<\/span><span class=\"pun\" style=\"color: #000000;\">(<\/span><span class=\"pln\" style=\"color: #000000;\">jjj1<\/span><span class=\"pun\" style=\"color: #000000;\">)\r\n<\/span><span class=\"typ\" style=\"color: #2b91af;\">Response<\/span><span class=\"pun\" style=\"color: #000000;\">.<\/span><span class=\"typ\" style=\"color: #2b91af;\">Write<\/span><span class=\"pun\" style=\"color: #000000;\">(<\/span><span class=\"str\" style=\"color: #800000;\">\"&lt;\/script&gt;\"<\/span><span class=\"pun\" style=\"color: #000000;\">)<\/span><\/code><\/pre>\n<p>In this way our cookie variable value will be exactly what we wanted &#8220;__cf_mob_redir&#8221;.<\/p>\n<p>But what if we need absolutely to send only the headers, for example to avoid\u00a0<span style=\"color: #222222;\">the page be returned before being able to set the cookie and send a header response?<\/span><\/p>\n<p>This line is the answer.<\/p>\n<pre class=\"default prettyprint prettyprinted\" style=\"color: #393318;\"><code><span class=\"typ\" style=\"color: #2b91af;\">Response<\/span><span class=\"pun\" style=\"color: #000000;\">.<\/span><span class=\"typ\" style=\"color: #2b91af;\">AddHeader <\/span><span class=\"str\" style=\"color: #800000;\">\"Set-Cookie\"<\/span><span class=\"pun\" style=\"color: #000000;\">, <\/span><span class=\"str\" style=\"color: #800000;\">\"nameKey=__cf_mob_redir; HttpOnly\"<\/span><\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following code line Response.Cookies(&#8220;test&#8221;)= &#8220;__cf_mob_redir&#8221; will produce a cookie named &#8220;test&#8221; whith value &#8220;%5F%5Fcf%5Fmob%5Fredir&#8221; Perhaps is not what we wanted. Even if we could decode the result when reading the cookie that string is very ugly. Could also happen that our responsibility is limited to write the right value and someone else will take [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":132,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[35,3],"tags":[63,36,64,58,61,60,59,62],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/08\/AspClassic.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p90hsv-2r","jetpack-related-posts":[{"id":131,"url":"https:\/\/www.danieledavi.com\/blog\/2014\/08\/html-parser-in-classic-asp\/","url_meta":{"origin":151,"position":0},"title":"HTML Parser in Classic ASP","author":"Daniele Dav\u00ec","date":"August 28, 2014","format":false,"excerpt":"Today I'll show you a script written in classic ASP that can use some server vulnerability to provide traffic from an unaware website to another one through another unaware server. It's quite simple, so I'm not going to explain it in details. This malicious code was founded on a server,\u2026","rel":"","context":"In &quot;Classic ASP&quot;","block_context":{"text":"Classic ASP","link":"https:\/\/www.danieledavi.com\/blog\/category\/programming\/classic-asp\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/08\/AspClassic.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":138,"url":"https:\/\/www.danieledavi.com\/blog\/2014\/09\/how-to-use-windows-registry-in-your-net-c-application\/","url_meta":{"origin":151,"position":1},"title":"How to use Windows registry in your .Net C# application","author":"Daniele Dav\u00ec","date":"September 5, 2014","format":false,"excerpt":"In this article I will show how to read and use in your .Net C# application informations stored in\u00a0the Windows registry. First of all let's see the easiest way to store some information in the server registry. You can use the \"regedit\" command to edit the register or you can\u2026","rel":"","context":"In &quot;.Net C#&quot;","block_context":{"text":".Net C#","link":"https:\/\/www.danieledavi.com\/blog\/category\/programming\/dot-net-c-sharp\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2014\/09\/csharp-image.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":607,"url":"https:\/\/www.danieledavi.com\/blog\/2020\/10\/product-owners-dont-need-to-be-technical-to-be-good\/","url_meta":{"origin":151,"position":2},"title":"Product owners don&#8217;t need to be technical to be good &#8211; part 1","author":"Daniele Dav\u00ec","date":"October 28, 2020","format":false,"excerpt":"Today I want to write about the product owner (PO) or product manager (PM) role and not to provide a definition or list responsibilities but address a specific myth. I am talking about the myth of the existence and the need of a technical PO.","rel":"","context":"In &quot;Agile&quot;","block_context":{"text":"Agile","link":"https:\/\/www.danieledavi.com\/blog\/category\/agile-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":791,"url":"https:\/\/www.danieledavi.com\/blog\/2021\/03\/changes-are-welcome\/","url_meta":{"origin":151,"position":3},"title":"Changes are Welcome","author":"Daniele Dav\u00ec","date":"March 10, 2021","format":false,"excerpt":"There are different levels of understanding\u00a0Agile.The first one is where you care about rules. You take every best practice, guide, book, training suggestion and you make a strict process out of context and without interpreting the reality. That's not Agile. That's you using Agile to cover your need of implementing\u2026","rel":"","context":"In &quot;Agile&quot;","block_context":{"text":"Agile","link":"https:\/\/www.danieledavi.com\/blog\/category\/agile-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":699,"url":"https:\/\/www.danieledavi.com\/blog\/2021\/02\/the-importance-of-trust-in-organisations\/","url_meta":{"origin":151,"position":4},"title":"The Importance of trust in organisations","author":"Daniele Dav\u00ec","date":"February 15, 2021","format":false,"excerpt":"Trust is a pillar for many organizations nowadays.I remember seeing on the\u00a0tv displays at the office\u00a0many times a day the ubiquitous message \"Microsoft is built on trust\" when I worked there.Many organizations following the trend come up with similar mottos, insert the trust narrative into their vision, mission, or values.\u2026","rel":"","context":"In &quot;Agile&quot;","block_context":{"text":"Agile","link":"https:\/\/www.danieledavi.com\/blog\/category\/agile-2\/"},"img":{"alt_text":"Not understanding the process","src":"https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2021\/03\/FollowingTheprocess.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2021\/03\/FollowingTheprocess.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2021\/03\/FollowingTheprocess.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2021\/03\/FollowingTheprocess.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.danieledavi.com\/blog\/wp-content\/uploads\/2021\/03\/FollowingTheprocess.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":609,"url":"https:\/\/www.danieledavi.com\/blog\/2020\/10\/product-owners-dont-need-to-be-technical-to-be-good-part-2\/","url_meta":{"origin":151,"position":5},"title":"Product owners don&#8217;t need to be technical to be good &#8211; part 2","author":"Daniele Dav\u00ec","date":"October 28, 2020","format":false,"excerpt":"In part one, I wrote about the myth of existence and need of technical product owners. We left our hypothetical PO at a party answering few questions around his or her product. As we saw, the product owner needs to own the product knowledge base. If you are a PO\u2026","rel":"","context":"In &quot;Agile&quot;","block_context":{"text":"Agile","link":"https:\/\/www.danieledavi.com\/blog\/category\/agile-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"amp_validity":null,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts\/151"}],"collection":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":4,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions\/156"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/media\/132"}],"wp:attachment":[{"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.danieledavi.com\/blog\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}