This has come from something ages ago and I can vaguely remember having the same problem myslef - but this is what was in my webconfig for that project.
Can't remember if works or not.
<!-- custom ERROR MESSAGES
Set mode="on" or "remoteonly" to enable custom error messages, "off" to disable. Add
<error> tags for each of the errors you want to handle. -->
<customErrors defaultRedirect="genericerror.htm" mode="RemoteOnly">
<!-- using mode="RemoteOnly" dishes out its own stuff -->
<error statusCode="404"
redirect="PageNotFound.htm"/>
<error statusCode="500"
redirect="InternalError.htm"/>
</customErrors>