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

Discussion in 'ASP .Net' started by Calvin Lai, Dec 30, 2003.

  1. Calvin Lai

    Calvin Lai Guest

    Does anyone know the difference and usage of them? Great thanks!
     
    Calvin Lai, Dec 30, 2003
    #1
    1. Advertising

  2. Calvin Lai

    bruce barker Guest

    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" <> wrote in message
    news:_emIb.21428$...
    > Does anyone know the difference and usage of them? Great thanks!
    >
    >
     
    bruce barker, Dec 31, 2003
    #2
    1. Advertising

  3. Calvin Lai

    Joerg Jooss Guest

    "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 Jooss, Dec 31, 2003
    #3
  4. Calvin Lai

    Calvin Lai Guest

    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" <> wrote in message
    news:#...
    >
    > 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" <> wrote in message
    > news:_emIb.21428$...
    > > Does anyone know the difference and usage of them? Great thanks!
    > >
    > >

    >
    >
     
    Calvin Lai, Dec 31, 2003
    #4
  5. Calvin Lai

    Calvin Lai Guest

    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" <> wrote in message
    news:...
    > "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
    >
     
    Calvin Lai, Dec 31, 2003
    #5
  6. Calvin Lai

    Calvin Lai Guest

    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" <> wrote in message
    news:g5CIb.185388$...
    > 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" <> wrote in message
    > news:#...
    > >
    > > 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" <> wrote in message
    > > news:_emIb.21428$...
    > > > Does anyone know the difference and usage of them? Great thanks!
    > > >
    > > >

    > >
    > >

    >
    >
     
    Calvin Lai, Dec 31, 2003
    #6
  7. Calvin Lai

    Joerg Jooss Guest

    "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
     
    Joerg Jooss, Dec 31, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Per Bolmstedt
    Replies:
    0
    Views:
    428
    Per Bolmstedt
    Mar 3, 2004
  2. Ricky K. Rasmussen

    Set Request.ContentEncoding from code?

    Ricky K. Rasmussen, May 11, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    6,146
    Steven Cheng[MSFT]
    May 28, 2004
  3. =?Utf-8?B?VG9t?=

    Web User Control and ResponseEncoding

    =?Utf-8?B?VG9t?=, Nov 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    472
    Scott Allen
    Nov 8, 2004
  4. Tom

    ResponseEncoding in Web User Control Page

    Tom, Nov 8, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    193
    Joerg Jooss
    Nov 12, 2004
  5. optimistx

    javascript charset <> page charset

    optimistx, Aug 14, 2008, in forum: Javascript
    Replies:
    2
    Views:
    278
    optimistx
    Aug 15, 2008
Loading...

Share This Page