Request.QueryString Collection Doesn't Get Umlauts

  • Thread starter Thread starter Axel Dahmen
  • Start date Start date
A

Axel Dahmen

Hi,

I've created an aspx page taking a query string argument as parameter.
Although I've correctly escaped umlauts in the query string, they do not
appear in the QueryString collection. If I give:
http://myComp/myPage.aspx?q=G%FCnther

Request.QueryString[0] yields "Gnther" instead of "Günther".

What's happening?

TIA
Axel Dahmen
 
You can convert the parameter with Server.UrlEncode before invoking the
url,then get the value of the parameter with Server.UrlDecode.
maybe help
 
Axel said:
Hi,

I've created an aspx page taking a query string argument as parameter.
Although I've correctly escaped umlauts in the query string, they do
not appear in the QueryString collection. If I give:
http://myComp/myPage.aspx?q=G%FCnther

Request.QueryString[0] yields "Gnther" instead of "Günther".

What's happening?

%FC is ü in ISO-8859-1 (or -15), but ASP.NET is using UTF-8 by default
to decode request parameters (including the query string). That leaves
you with the following choices:

1. Change your application's <globalization/> element in web.config to
use ISO-8859-1 as requestEncoding (and in this case preferably
responseEncoding as well).

2. If you want to change the request encoding through code, set in it
your HttpApplication's (e.g. global.asax) Application_BeginRequest
callback:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
//This will override the <globalization/> entry with ISO-8859-1
Request.ContentEncoding = Encoding.GetEncoding(28591);
}

3. Make sure the client is using UTF-8 when encoding request
parameters. How to achieve that depends on your web client. Since
you're using a Web Form, it's most likely that the browser uses the
wrong encoding. Did you add some META tag to your Web Form, or is your
browser configured to use ISO-8859-1 exlcusively?

Cheers,
 
Thanks a lot, Jörg! You helped me a lot!

Actually, what I did was simply typing "javascript:escape('Günther')" into
the address bar of my browser. Didn't know that there were several encodings
allowed on the query string.

Now I've created a simply GET form and set the encoding to UTF-8 manually.

Regards,
Axel

-----------
Joerg Jooss said:
Axel said:
Hi,

I've created an aspx page taking a query string argument as parameter.
Although I've correctly escaped umlauts in the query string, they do
not appear in the QueryString collection. If I give:
http://myComp/myPage.aspx?q=G%FCnther

Request.QueryString[0] yields "Gnther" instead of "Günther".

What's happening?

%FC is ü in ISO-8859-1 (or -15), but ASP.NET is using UTF-8 by default
to decode request parameters (including the query string). That leaves
you with the following choices:

1. Change your application's <globalization/> element in web.config to
use ISO-8859-1 as requestEncoding (and in this case preferably
responseEncoding as well).

2. If you want to change the request encoding through code, set in it
your HttpApplication's (e.g. global.asax) Application_BeginRequest
callback:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
//This will override the <globalization/> entry with ISO-8859-1
Request.ContentEncoding = Encoding.GetEncoding(28591);
}

3. Make sure the client is using UTF-8 when encoding request
parameters. How to achieve that depends on your web client. Since
you're using a Web Form, it's most likely that the browser uses the
wrong encoding. Did you add some META tag to your Web Form, or is your
browser configured to use ISO-8859-1 exlcusively?

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top