Solved

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

Posted on 2013-05-20
5
776 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
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

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

Expert Comment

by:Rob Jurd, EE MVE
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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now