We help IT Professionals succeed at work.
Get Started

Javascript encoding cookie to be read by asp.net in different encoding

lefodnes asked
Last Modified: 2015-04-12
I'm having difficulties understanding the encoding "circus"... Again.
I'm writing a cookie in javascript in a plain HTML file, like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
        document.cookie = "testCookie=TestingÆØÅ";


Open in new window

Then I'm trying to read this into a string in a .ashx file in the same directory:
<%@ WebHandler Language="C#" Class="readcookie" %>

using System;
using System.Web;

public class readcookie : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        HttpCookie hc = context.Request.Cookies["testCookie"];
        if (hc != null)
            string s = hc.Value;
    public bool IsReusable {
        get {
            return false;


Open in new window

Running that ashx-file gives me

Open in new window

I don't see the ÆØÅ

Checking the Request Headers in the debugging panel in Google Chrome for the ashx file, I see this:
GET /readcookie.ashx HTTP/1.1
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: nb-NO,nb;q=0.8,no;q=0.6,nn;q=0.4,en-US;q=0.2,en;q=0.2
Cookie: testCookie=TestingÆØÅ

Open in new window

No ÆØÅ there either...
Watch Question
Fixer of Problems
Most Valuable Expert 2014
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE