The problem
When I try to retrieve the query string parameter the accent decoding doesn’t work correctly.
Environment & info
- Website html/js and server side .net Framework 4.0 (written in vb)
- I don’t have access to the server, and therefore not even to IIS
- In the web.config I set the encoding to UTF-8:
<globalization uiCulture="it" culture="it-IT" requestEncoding="utf-8" responseEncoding="utf-8"/>
- I’m quite convinced that this problem wasn’t there until a few days (months?) ago.
- I can’t provide the site to check the problem on.
Code & test
$txtSearchSimple.val() is an input/textbox that contains: “perchè questo”
//JS
console.log(encodeURIComponent($txtSearchSimple.val()));
window.location = '/page.aspx?t=' + encodeURIComponent($txtSearchSimple.val());
In console the browser write correctly: perch%C3%A8%20questo
But on VB:
Session("TEST_Acc") = Request.QueryString("t") & " --> "
Session("TEST_Acc") &= Uri.UnescapeDataString(Request.QueryString("t")) & " -> "
Session("TEST_Acc") &= HttpUtility.UrlDecode(Request.QueryString("t")) & " -> "
Session("TEST_Acc") &= HttpUtility.UrlDecode(Request.QueryString("t")) & " -> "
Session("TEST_Acc") &= HttpUtility.UrlDecode(Request.QueryString("t"), Encoding.UTF8) & " -> "
Session("TEST_Acc") &= HttpUtility.UrlDecode(Uri.UnescapeDataString(Request.QueryString("t")), Encoding.UTF8)
Session("TEST_Acc2") = HttpUtility.UrlDecode(Uri.UnescapeDataString("perch%C3%A8%20questo"), Encoding.UTF8) & " -> "
Session("TEST_Acc2") &= HttpUtility.UrlDecode(Uri.UnescapeDataString("perchè questo"), Encoding.UTF8)
The results:
'TEST_Acc:
perchè questo --> perchè questo -> perchè questo -> perchè questo -> perchè questo
'TEST_Acc2:
perchè questo -> perchè questo
I also attach the result of the chrome request/response
I don’t understand how it is possible that between the request (which seems correct) and the server-side fetch it is decoded incorrectly even before I can query the value with the Request.QueryString
.
Thank you very much for the help you want to give me.