ASP.NET & W3C Validation

This may be a coding question, but may also be a server setting issue, so I'm posting here...

When attempting to validate an ASP.NET page from here at W3C (http://validator.w3.org/), you get the following error:

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.

If you validate the exact same page in classic ASP, you get no errors.

For examples check:
Untitled Document
Untitled Document

I found this article (ASP.NET and XHTML) addressing .NET and W3C validation that seems to indicate this may be due to .NET not recognizing the W3C validation service as a "browser". Adding a browser definition such as below, should help (if this is the case).

You can configure your application to send the correct XHTML-conformant markup to the validation service by creating a browser definition for the validation service's user agent string. For example, the W3C Markup Validation Service reports a user agent that begins with "W3C_Validator". To create a browser definition for the W3C validator, you can create a .browser file in your application's App_Browsers folder (you can name the .browsers file anything you like) and then add the following browsers element.

Code:
<browsers>
  <browser id="W3C_Validator" parentID="default">
    <identification>
        <userAgent match="^W3C_Validator" />
    </identification>
    <capabilities>
      <capability name="browser"              value="W3C Validator" />
      <capability name="ecmaScriptVersion"    value="1.2" />
      <capability name="javascript"           value="true" />
      <capability name="supportsCss"          value="true" />
      <capability name="tables"               value="true" />
      <capability name="tagWriter" 
         value="System.Web.UI.HtmlTextWriter" />
      <capability name="w3cdomversion"        value="1.0" />
    </capabilities>
  </browser>
</browsers>

[/QUOTE]

Is this something that needs to be done server-side? Or is this something I need to do on an account-by-account basis?

Or, I guess another option is that the error above has nothing to do with the .browsers file, in which case, does anybody know what I need to do to get .NET to validate?
 
I had a look at your output using SamSpade.

The asp page contains this http header:

Content-Type: text/html

The aspx page has this.

Content-Type: text/html; charset=utf-8

The problem doesn't occur with asp because the meta data is the only place this is defined.

I guess there are several ways to fix it. That string is defined by the Page.ContentType property. You can set that with an @Page directive.

I think there is something you can set in your web.config so that is defaults for all pages.

But ... utf-8 tends to be the recommended standard these days so you might be better just changing the meta data to utf-8.

Of course the code you tell the browser should be the same as what your pages are saved as. This unicode encoding stuff is confusing. This page by Joel Spolsky is a good explanation of what it is all about.

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) - Joel on Software

Cheers
Ross
 
Back
Top