Solved

Problem with ÆØÅ characters when using http headers (Web API)

Posted on 2013-05-20
5
798 Views
Last Modified: 2013-06-18
In my ASP.Net Web Api I have a Get function where input info is sent in the http header. It works fine, except when the http header contains Norwegian characters like Æ, Ø and Å. This characters is transformed to æ ø Ã¥. When the same characters (Æ,Ø,Å) are sent as parameters in the URL it works fine. When testing the script on my local PC it works fine to send Æ, Ø and Å in the http header as well.

I don't know why norwegian characters can't be sent in the http header, but I guess this is an encoding / charset problem. After hours of testing I still can't find any way fo fix it.

Web.config:

<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="nb-NO" uiCulture="nb-NO" />

Open in new window


Getting Http Header:
 
private string GetHeader(string key)
{
    var header = "";
    if (Request.Headers.Contains(key))
    {
        IEnumerable<string> values = new List<string>();
        Request.Headers.TryGetValues(key, out values);
        if (!string.IsNullOrEmpty(values.First())) header = values.First();
    }
    return header;
}
 
var headerUserName = GetHeader("UserName");

Open in new window


Request headers

User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
UserName: ÆØÅ
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
 

Response headers

Date: Wed, 15 May 2013 12:46:19 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: application/json; charset=utf-8
Content-Length: 4174
0
Comment
Question by:webressurs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 39182964
Is it browser specific problem?
0
 
LVL 43

Expert Comment

by:Rob
ID: 39183095
The request is using ISO-8859-1 before utf-8  the response is just utf-8. Try removing ISO-8859-1
0
 
LVL 1

Author Comment

by:webressurs
ID: 39185050
The only solution that works for me is to UrlEncode the HTTP Header value, and UrlDecode it on the server.
0
 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 39186307
That sounds like a solution to me.  is that not suitable?
0
 
LVL 1

Author Closing Comment

by:webressurs
ID: 39256332
That was the solution :)
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question