?
Solved

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

Posted on 2013-05-20
5
Medium Priority
?
808 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 1500 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

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
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

800 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