I've used the <customErrors> section of the web.config file to handle this in the past. This works in MVC and/or webforms.
If you don't like that approach, check out this article for a custom solution, and this one for some workarounds on the default architecture.