Use Custom Error Pages

Problem

You want to show a custom error page when an unhandled exception or HTTP error occurs.

Solution

Specify a custom error page using the <customErrors> element in the web.config file for the application.

Discussion

Custom error pages allow you to specify a page that will be returned to the user if an unhandled .NET exception occurs in your page code. Custom error pages aren’t a replacement for good error handling; they just allow your application to maintain its professional appearance in the event of an unexpected error. Custom error pages can also be used to catch HTTP errors (for example, if the user requests a page that does not exist) and return descriptive error pages.

You can define custom errors at the virtual directory ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.