Thursday, April 12, 2012

ASP.NET validation controls produce invalid XHTML markup when referencing WebResource.axd

Doing some .NET work recently and came across an issue that was pretty frustrating.  I had valid XHTML output until I added a .NET validation control to the page.  The result was that there were some script tags added to the HTML that looked like this:

<script src="/WebResource.axd?d=BSOU...Q%3d_f&t=6346...00"
type="text/javascript"></script> 

Note that the "&" is not escaped.  I decided to override the page render and use a regex to escape the URLs.  My solution is below: