Why is ASP.NET changing character encoding of documents?

Discussion in 'ASP .Net' started by John Dalberg, Oct 17, 2005.

  1. John Dalberg

    John Dalberg Guest

    The below html validates correctly on w3.org's html validator when the file
    has an html extension. When the same file gets an aspx extension, I get the
    error below from the validator. This tells me that ASP.NET is changing the
    character encoding in the http header. How can this be corrected so that
    aspx pages validate correctly?

    Error Message:
    "The character encoding specified in the HTTP header (utf-8) is different
    from the value in the <meta> element (iso-8859-1). I will use the value
    from the HTTP header (utf-8) for this validation."


    html file:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    </body>
    </html>



    --
    John Dalberg
     
    John Dalberg, Oct 17, 2005
    #1
    1. Advertising

  2. That's really strange.

    When I check : http://asp.net.do/test/w3cvalidate.aspx
    which has the *exact* same content as you provided
    ( I copied and pasted it ) it passes validation, and the
    encoding is reported as iso-8859-1.

    Here's the check URL :

    http://validator.w3.org/check?uri=h...=Inline&ss=1&outline=1&sp=1&No200=1&verbose=1

    What gives, John ?



    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "John Dalberg" <2> wrote in message
    news:...
    >
    > The below html validates correctly on w3.org's html validator when the file
    > has an html extension. When the same file gets an aspx extension, I get the
    > error below from the validator. This tells me that ASP.NET is changing the
    > character encoding in the http header. How can this be corrected so that
    > aspx pages validate correctly?
    >
    > Error Message:
    > "The character encoding specified in the HTTP header (utf-8) is different
    > from the value in the <meta> element (iso-8859-1). I will use the value
    > from the HTTP header (utf-8) for this validation."
    >
    >
    > html file:
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head>
    > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    > <title>Untitled Document</title>
    > </head>
    >
    > <body>
    > </body>
    > </html>
    >
    >
    >
    > --
    > John Dalberg
     
    Juan T. Llibre, Oct 17, 2005
    #2
    1. Advertising

  3. I found out what gives.

    My default encoding in web.config was iso-8859-1.

    When I run that page with
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    both charsets are the same, so everything is OK.

    When I change web.config to use utf-8, I get the same error you reported,
    but all that means is that you cannot override an asp.net charset setting
    with a META tag.

    The web.config setting takes precedence over the meta tag.

    In sum, if you want to change the web.config setting ( or the
    default setting for asp.net, which is utf-8 ), use the @Page directive :

    <%@ Page ResponseEncoding="iso-8859-1" %>
    and get rid of the META tag you tried to use.

    Check the valid result, eliminating the META tag,
    and using the above @Page setting, with the default
    encoding set to utf-8 in web.config.

    http://validator.w3.org/check?uri=h...=Inline&ss=1&outline=1&sp=1&No200=1&verbose=1

    best regards,



    Juan T. Llibre, ASP.NET MVP
    ASP.NET FAQ : http://asp.net.do/faq/
    Foros de ASP.NET en Español : http://asp.net.do/foros/
    ======================================
    "Juan T. Llibre" <> wrote in message
    news:...
    > That's really strange.
    >
    > When I check : http://asp.net.do/test/w3cvalidate.aspx
    > which has the *exact* same content as you provided
    > ( I copied and pasted it ) it passes validation, and the
    > encoding is reported as iso-8859-1.
    >
    > Here's the check URL :
    >
    > http://validator.w3.org/check?uri=h...=Inline&ss=1&outline=1&sp=1&No200=1&verbose=1
    >
    > What gives, John ?
    >
    >
    >
    > Juan T. Llibre, ASP.NET MVP
    > ASP.NET FAQ : http://asp.net.do/faq/
    > Foros de ASP.NET en Español : http://asp.net.do/foros/
    > ======================================
    > "John Dalberg" <2> wrote in message
    > news:...
    >>
    >> The below html validates correctly on w3.org's html validator when the file
    >> has an html extension. When the same file gets an aspx extension, I get the
    >> error below from the validator. This tells me that ASP.NET is changing the
    >> character encoding in the http header. How can this be corrected so that
    >> aspx pages validate correctly?
    >>
    >> Error Message:
    >> "The character encoding specified in the HTTP header (utf-8) is different
    >> from the value in the <meta> element (iso-8859-1). I will use the value
    >> from the HTTP header (utf-8) for this validation."
    >>
    >>
    >> html file:
    >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >> <html xmlns="http://www.w3.org/1999/xhtml">
    >> <head>
    >> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    >> <title>Untitled Document</title>
    >> </head>
    >>
    >> <body>
    >> </body>
    >> </html>
    >>
    >>
    >>
    >> --
    >> John Dalberg

    >
    >
     
    Juan T. Llibre, Oct 17, 2005
    #3
    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. Replies:
    1
    Views:
    23,512
    Real Gagnon
    Oct 8, 2004
  2. raavi
    Replies:
    2
    Views:
    923
    raavi
    Mar 2, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,128
    Smokey Grindel
    Dec 2, 2006
  4. helzer
    Replies:
    0
    Views:
    140
    helzer
    Oct 19, 2007
  5. David Komanek
    Replies:
    11
    Views:
    303
    David Komanek
    Sep 30, 2003
Loading...

Share This Page