Why is ASP.NET changing character encoding of documents?

J

John Dalberg

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>
 
J

Juan T. Llibre

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top