The following code line
will produce a cookie named “test” whith value “%5F%5Fcf%5Fmob%5Fredir”
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 care of reading the expected value.
What to do?
First, is useful to know that encoding the special character _ (underscore) in ASP as chr(95) or as HTML entity _ will not solve the situation. The same for any other special characters.
In this way our cookie variable value will be exactly what we wanted “__cf_mob_redir”.
But what if we need absolutely to send only the headers, for example to avoid the page be returned before being able to set the cookie and send a header response?
This line is the answer.
Response.AddHeader "Set-Cookie", "nameKey=__cf_mob_redir; HttpOnly"