After creating your ASP.NET Web pages, you might want to check whether they will render correct XHTML. If the page contains ASP.NET Web server controls, there is no way to check the page while writing it because the controls render XHTML only when the page runs.
Note: |
|---|
Some visual designers, such as Visual Studio, can provide design-time XHTML validation of the page's markup. |
To check the validity of the XHTML for your pages, you must use a service that runs the page and checks its output. A typical strategy is to deploy your pages to a publicly available server. The server can be a test server; it does not have to be a production server. However, it must be open to the Internet. You can then use a validation service that can read your pages programmatically.
A popular service is the W3C Markup Validation Service, which is maintained by the World Wide Web Consortium. To use this validator, enter the URL of the page that you want the service to check. The validation site requests the page and produces a report of any errors that it finds. Alternatively, you can save the source for a Web page and submit it as a file to the validation service. For more information about this validation service, see the W3C Web site.
If the page that you are checking contains dynamic content, or if users can personalize Web pages in your site, you must be sure to test pages with different content to be sure all possible content in the page is valid. In some cases, this can be difficult because the variation in possible page output is too great to be able to test effectively.
Configuring Browser Capabilities for Markup Validation
When a page is processed, ASP.NET examines information in the request about the current browser, and based on the browser type (user agent string), renders markup that is appropriate for that browser. For more information, see ASP.NET Web Server Controls and Browser Capabilities.
If you submit an ASP.NET Web page to a validation service such as the W3C Markup Validation Service, ASP.NET might render a version of the page that does not conform to XHTML standards. This is because the validator service does not report itself as a browser type that ASP.NET recognizes, such as Internet Explorer or Mozilla. When ASP.NET cannot recognize the browser type, it defaults to rendering downlevel markup, which does not include XHTML-conformant elements and attributes, or features such as cascading style sheet styles.
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.
<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>
For more information about creating browser definitions, see Browser Definition File Schema (browsers Element).