views:

48

answers:

2

Hi everyone, My problem is not too hard but really annoying.

I'm sending values to Generic Handler via Ajax like that way.

xmlHttpReq.open("GET", "AddMessage.ashx?" + (new Date().getTime()) +"&Message=" + Message,true);

when message contains İ,ç,ö,ğ,ü,ı they are looking like that on Handler ������� In context.Request.RawURL İ,ç,ö,ğ,ü,ı these characters are looking as it should. But in context.Request.Url they are looking like ������� and when i want QueryString values it gives me ������� what can i do?

+1  A: 

A couple of things to check:

  1. In web.config you've set UTF-8:

    <system.web>
        <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
        ...
    </system.web>
    
  2. You've a proper meta tag in your HTML page:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
  3. All your .aspx, .ascx, .master, .ashx,... files are saved as UTF-8 with BOM on the hard drive.

  4. You are properly URL encoding parameters before sending them (using the encodeURIComponent method):

    xmlHttpReq.open(
        "GET", 
        "AddMessage.ashx?" + 
            (new Date().getTime()) + 
            "&Message=" + encodeURIComponent(Message),
        true
    );
    
Darin Dimitrov
Thanks for quickly reply. But its not helping i'm already tried it. But i found the answer here. http://stackoverflow.com/questions/1578398/asp-net-ajax-query-string-parameters-using-iso-8859-1-encoding
Ümit Akkaya
Normally if you perform the 4 steps I suggested you, you won't need to do the conversions from the different encodings suggested in this answer.
Darin Dimitrov
A: 

I found answer on this link. http://stackoverflow.com/questions/1578398/asp-net-ajax-query-string-parameters-using-iso-8859-1-encoding

// original parameterized value with invalid characters
string paramQs = context.Request.QueryString["param"];
// correct parsed value from query string parameter
string param = Encoding.UTF8.GetString(Encoding.GetEncoding("iso8859-1").GetBytes(paramQs));
Ümit Akkaya