Define the location of ASP.NET client validation scripts
Over the weekend a bank went live with a system I’ve been working on for the last year. The system is now in production and things are running smoothly, but that is not to say there weren’t any hitches.
The one problem was that the submit button on ASP.NET pages does not work after you install the .NET Framework 1.1 Service Pack 1. The solution didn’t seem too difficult. Just call aspnet_regiis -c and all will be right with the world. That solution would usually work well: it would replace the following erroneous code in WebUIValidation.js:
function ValidatorCommonOnSubmit() {
event.returnValue = !Page_BlockSubmit;
Page_BlockSubmit = false;
}
with the following correct code…
function ValidatorCommonOnSubmit() {
var result = !Page_BlockSubmit;
Page_BlockSubmit = false;
event.returnValue = result;
return result;
}
However, after doing this the problem was still there. The submit button still failed, but a search of every WebUIValidation.js file on the server proved that the correct versions were in place. I was also able to prove (by hacking the URL) that the old script file was definitely being downloaded to the client! So where was it coming from?
The answer is that the file was coming from a completely different server because of the bank’s VirtualVault security software (basically, the server to which the root IP address mapped was not the server to which the virtual directory mapped). We now had a problem because we did not have access to the other server and so we could not apply the fix.
The solution was obviously to tell the browser to look elsewhere for the client validation scripts. By default, the browser gets the script from the root relative path:
/aspnet_client/system_web/1_1_4322/WebUIValidation.js
This is defined in machine.config as follows:
<system.web>
<webcontrols
clientScriptsLocation="/aspnet_client/system_web/1_1_4322/"/>
</system.web>
All I needed to do was to override this setting for our web application by adding the same setting to
web.config and changing the path:<system.web>
<webcontrols
clientScriptsLocation="/{VirtualDir}/aspnet_client, etc."/>
</system.web>
I hope somebody else finds this useful (…when I get round to submitting this blog to the search engines).
