By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

Why is ASP.NET changing character encoding of documents?

P: n/a

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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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=ht...00=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" <jj**@hotmail.com2> wrote in message
news:s5***************************@40tude.net...

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

Nov 19 '05 #2

P: n/a
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=ht...00=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" <no***********@nowhere.com> wrote in message
news:e0**************@TK2MSFTNGP14.phx.gbl...
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=ht...00=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" <jj**@hotmail.com2> wrote in message
news:s5***************************@40tude.net...

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


Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.