Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Response.CharSet Vs Response.ContentEncoding Vs responseEncoding property in web.Config

16 views
Skip to first unread message

Calvin Lai

unread,
Dec 30, 2003, 4:38:02 PM12/30/03
to
Does anyone know the difference and usage of them? Great thanks!


bruce barker

unread,
Dec 30, 2003, 10:13:10 PM12/30/03
to

Response.ContentEncoding - specifies whether the data is ascii or a unicode
variant.
Response.CharSet - specifies what charset was used with the encoding.
(English, French, Chinese,etc), this is because two characters can be
encoded to the same value. this even happens with unicode, because the
pictographic languages are all mapped to a common set.

these are settable in your code behind. there are Page and web config
setting for these that you can use to set the default, or you can override
them in you code.


-- bruce (sqlwork.com)

"Calvin Lai" <calvi...@i010.com> wrote in message
news:_emIb.21428$INs....@twister01.bloor.is.net.cable.rogers.com...

Joerg Jooss

unread,
Dec 31, 2003, 5:17:20 AM12/31/03
to
"Calvin Lai" wrote:

> Does anyone know the difference and usage of them? Great thanks!

HttpResponse.ContentEncoding sets the Encoding object of the underlying
response stream *and* sets the charset of the content-type if
applicable. That's useful if you want to override the default encoding
specified in web.config.

HttpResponse.CharSet only sets the charset of the content-type and does
not effect the actual encoding applied to the output stream -- which
makes it of limited use as far as I'm concerned.

Note that nothing prevents you from doing stuff like
Response.ContentEncoding = Encoding.GetEncoding("Windows-1252");
Response.Charset = "UTF-8";

which is obviously utter nonsense, but sent to the browser anyway ;->

Cheers,
--
Joerg Jooss
joerg...@gmx.net

Calvin Lai

unread,
Dec 31, 2003, 10:39:56 AM12/31/03
to
Thanks for the clarification. However one problem remaining:
If my web application now has the responseEncodig set as iso8859-1, and the
ChatSet of resposne set as "big5". The unicode data retrieved from database
has no problem displaying in the client side browser.

How could I transform (using Text.Encoding.Convert, GetString, Get Bytes
methods) the data so that the client can still display correctly if I
change the responseEncoding to big5? Is there any way? Thanks a lot. I have
tried so many diferent combinations (which might still be wrong tho). I
really need help here.

Calvin


"bruce barker" <nospam...@safeco.com> wrote in message
news:#6WqGw0z...@TK2MSFTNGP12.phx.gbl...

Calvin Lai

unread,
Dec 31, 2003, 10:40:00 AM12/31/03
to
Thanks for the clarification. However one problem remaining:
If my web application now has the responseEncodig set as iso8859-1, and the
ChatSet of resposne set as "big5". The unicode data retrieved from database
has no problem displaying in the client side browser.

How could I transform (using Text.Encoding.Convert, GetString, Get Bytes
methods) the data so that the client can still display correctly if I
change the responseEncoding to big5? Is there any way? Thanks a lot. I have
tried so many diferent combinations (which might still be wrong tho). I
really need help here.

Calvin
"Joerg Jooss" <joerg...@gmx.net> wrote in message
news:u6mVHd4...@tk2msftngp13.phx.gbl...

Calvin Lai

unread,
Dec 31, 2003, 10:42:38 AM12/31/03
to
Here is a snipplet of the code that I used: (originalStirng containg some
chinese characters previously stored using iso8859-1)

System.Text.Encoding originalEncoding =
System.Text.Encoding.GetEncoding("iso8859-1");
System.Text.Encoding destEncoding =
System.Text.Encoding.GetEncoding("big5");
byte[] originalBytes =
originalEncoding.GetBytes(originalString.ToString());
byte[] destBytes =
System.Text.Encoding.Convert(originalEncoding, destEncoding, originalBytes);
Response.Write(destEncoding.GetString(destBytes) + "<BR>"); <--
Still doens't work. Same string retruned

"Calvin Lai" <calvi...@i010.com> wrote in message

news:g5CIb.185388$2We1....@news04.bloor.is.net.cable.rogers.com...

Joerg Jooss

unread,
Dec 31, 2003, 1:55:25 PM12/31/03
to
"Calvin Lai" wrote:

> Thanks for the clarification. However one problem remaining:
> If my web application now has the responseEncodig set as iso8859-1,
> and the ChatSet of resposne set as "big5". The unicode data
> retrieved from database has no problem displaying in the client side
> browser.

As I said, only setting CharSet is nonsensical if the real encoding is
different from that.

> How could I transform (using Text.Encoding.Convert, GetString, Get
> Bytes methods) the data so that the client can still display
> correctly if I change the responseEncoding to big5? Is there any
> way? Thanks a lot. I have tried so many diferent combinations (which
> might still be wrong tho). I really need help here.

Calvin,

I'm kind of lost. What are you're trying to achieve? Do you want to use
ISO-8859-1 as default response encoding and Big5 in special cases (or
vice versa)? Anyway, set the <globalization /> in web.config to the
desired default encoding and set ContentEncoding to the desired "special
case" encoding instance.

0 new messages