Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Response.CharSet Vs Response.ContentEncoding Vs responseEncoding property in web.Config

Reply
Thread Tools

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

 
 
Calvin Lai
Guest
Posts: n/a
 
      12-30-2003
Does anyone know the difference and usage of them? Great thanks!


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      12-31-2003

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" <(E-Mail Removed)> wrote in message
news:_emIb.21428$(E-Mail Removed). cable.rogers.com...
> Does anyone know the difference and usage of them? Great thanks!
>
>



 
Reply With Quote
 
 
 
 
Joerg Jooss
Guest
Posts: n/a
 
      12-31-2003
"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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Calvin Lai
Guest
Posts: n/a
 
      12-31-2003
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" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
>
> 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" <(E-Mail Removed)> wrote in message
> news:_emIb.21428$(E-Mail Removed). cable.rogers.com...
> > Does anyone know the difference and usage of them? Great thanks!
> >
> >

>
>



 
Reply With Quote
 
Calvin Lai
Guest
Posts: n/a
 
      12-31-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "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
> (E-Mail Removed)



 
Reply With Quote
 
Calvin Lai
Guest
Posts: n/a
 
      12-31-2003
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" <(E-Mail Removed)> wrote in message
news:g5CIb.185388$(E-Mail Removed). cable.rogers.com...
> 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" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
> >
> > 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" <(E-Mail Removed)> wrote in message
> > news:_emIb.21428$(E-Mail Removed). cable.rogers.com...
> > > Does anyone know the difference and usage of them? Great thanks!
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Joerg Jooss
Guest
Posts: n/a
 
      12-31-2003
"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.

Cheers,
--
Joerg Jooss
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
specifying responseencoding Krishna ASP General 1 12-02-2009 01:58 PM
responseEncoding James T. ASP .Net 1 05-05-2005 01:27 PM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM
ResponseEncoding in Web User Control Page Tom ASP .Net Web Controls 1 11-12-2004 09:51 PM
Web User Control and ResponseEncoding =?Utf-8?B?VG9t?= ASP .Net 1 11-08-2004 01:09 PM



Advertisments