Currently, Web developers want their websites to comply with the XHTML standard (if you do not know what the XHTML standard is, see web standards and ASP. NET-Part 1 XHTML Introduction ). When developing ASP. Net-based web programs that comply with XHTML standards, we need to constantly view the rendered ASPX page source files and copy & Paste to some online XHTML validator. Of course, this is not difficult in small and simple web programs. However, with the expansion of the program scale, the inconvenient side of this solution is gradually revealed. Alternatively, you can provide a "verify XHTML" link in the footer to point to an address, which then obtains your page and performs verification, however, this method cannot be used when developing pages that require authentication (such as the Hotmail inbox) or when the development environment does not have persistent network connections.
Bruusi and Josh developed an ASP. NET 2.0 validator module (Note: it can be used only for ASP. NET 2.0 Program), you can automatically check whether the page meets the XHTML standard during page rendering, and display the verification results on the page (you can customize the display area ).
This validator module will automatically download the latest DTD file from W3C Based on the doctype of the page during each page rendering to verify your page, these DTD files are cached locally so that you can develop and verify them offline.
You can find this validator module in http://www.thejoyofcode.com/Validator_Module.aspx in English and the latest updates.
Now let's take a look at the next page using the validator module. Here, I simply use a button to switch the line break of the text above a label (<br> in HTML, <br/> in XHTML ), to make the page switch between valid and invalid XHTML.
Valid:
Invalid:
You can find more sample programs at http://www.thejoyofcode.com/validatormodule.
Let's take a look at how to use this validator module. First, download the assembly to be referenced in the http://www.thejoyofcode.com/uploads/ValidatorModule.zip and add references to it in your web site.
Then, modify your web. config file according to the sample Web. config file in the downloaded compressed package. You must add the following content in the <configuration> section:
The mode attribute of validatormodule can be HTML, htmlfloat, comments, or custom. If you select Custom, you also need to write the ivalidationrenderer interface implementation. You can specify the file type to be verified in the pageextensions section. You can specify the content type to be verified in the contenttypes section.
<! -- Setup the custom configuration section -->
<Configsections>
<Section name = "validatormodule" type = "tjoc. Web. validator. validatorconfighandler, tjoc. Web. validator"/>
</Configsections>
<! -- Configure the validator -->
<Validatormodule enabled = "true" mode = "htmlfloat">
<Pageextensions>
<Add value = ". aspx"/>
</Pageextensions>
<Contenttypes>
<Add value = "text/html"/>
</Contenttypes>
</Validatormodule>
You can also add the following (optional) content to access W3C through the proxy server:
<Proxy Server = "proxyserver" Port = "80" Domain = "domainname" username = "username" Password = "password"/>
Finally, add the following content in the <system. Web> section:
<! -- Add the validator to the HTTP modules collection -->
<Httpmodules>
<Add type = "tjoc. Web. validator. validatormodule, tjoc. Web. validator" name = "validatormodule"/>
</Httpmodules>
OK, everything is fine. Now you can check whether your page meets the XHTML standard anytime and anywhere!
Sample programs starting with this article can be downloaded here: http://files.cnblogs.com/dflying/ValidatorModuleDemo.zip
Validator module can be downloaded here: http://www.thejoyofcode.com/uploads/ValidatorModule.zip
If you want to study the validator Module source program, you can contact bruusi and Josh in the http://www.thejoyofcode.com/contact_us.aspx.