Response.Redirect: Need ISO-8859-1 instead of utf-8

P

Peter Laan

I need to redirect the user to an external page and include some information
in the querystring (is this possible to do as a post instead of get?) I'm
using Response.Redirect. The problem occurs if the information contains
local characters (like åäö.) The external page can only handle ISO-8859. If
I check the browser's address bar, local characters are in 'plain' text. I
tried using Server.Encode, but then I got them in utf-8. Is it possible to
get ISO-8859-1?

Peter
 
M

MasterGaurav

Oops!
ERRATA:

In ASP and ASP.Net, content type and charset are set independently, and
are methods on the response object. To set the charset, use e.g.:

<% Response.Charset="utf-8"%>

In ASP.Net, setting Response.ContentEncoding will take care both of the
charset parameter in the HTTP Content-Type as well as of the actual
encoding of the document sent out (which of course have to be the
same). The default can be set in the globalization element in
Web.config (or Machine.config, which is originally set to UTF-8).

For web.config / machine.config file - check the globalization element.

I would suggest -- prefer using meta tag.


--
Cheers,
Gaurav Vaish
http://mastergaurav.org
http://mastergaurav.blogspot.com
------------------------------------
 
P

Peter Laan

MasterGaurav said:
Oops!
ERRATA:

In ASP and ASP.Net, content type and charset are set independently, and
are methods on the response object. To set the charset, use e.g.:

<% Response.Charset="utf-8"%>

In ASP.Net, setting Response.ContentEncoding will take care both of the
charset parameter in the HTTP Content-Type as well as of the actual
encoding of the document sent out (which of course have to be the
same). The default can be set in the globalization element in
Web.config (or Machine.config, which is originally set to UTF-8).

For web.config / machine.config file - check the globalization element.

I would suggest -- prefer using meta tag.

Setting Response.Charset didn't work. I tried the following:

Response.Charset = "ISO-8859-1";
Response.Redirect(url);



If I enter 'pÅÄÖp' as the name, I get the following in the querystring:

name=p%c3%85%c3%84%c3%96p

The external page shows other weird characters.


Peter
 
P

Peter Laan

Found a solution (perhaps not the easiest one, but it seems to work):

// string str will be converted to string ret.
System.Text.Encoding enc = System.Text.Encoding.GetEncoding(28591);

byte[] byteArray = new byte[str.Length];

int count = enc.GetBytes(str, 0, str.Length, byteArray, 0);

string[] cs = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b",
"c", "d", "e", "f"};

for (int i = 0; i < count; i++) {

int lb = 0;

int hb = System.Math.DivRem((int) byteArray, 16, out lb);

ret += "%" + cs[hb] + cs[lb];

}



Peter
 
J

Joerg Jooss

Peter said:
I need to redirect the user to an external page and include some
information in the querystring (is this possible to do as a post
instead of get?) I'm using Response.Redirect. The problem occurs if
the information contains local characters (like åäö.) The external
page can only handle ISO-8859. If I check the browser's address bar,
local characters are in 'plain' text. I tried using Server.Encode,
but then I got them in utf-8. Is it possible to get ISO-8859-1?

See System.Web.HttpUtility. Unlike System.Web.HttpServerUtility, it
allows you to specify a character encoding directly.

Cheers.
 
P

Peter Laan

Joerg Jooss said:
See System.Web.HttpUtility. Unlike System.Web.HttpServerUtility, it
allows you to specify a character encoding directly.

Thanks! That's exactly what I was looking for.

Peter
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top