Creating an Error Page

If you want to add application-wide error handling so that any unhandled error takes you to a page of your choosing (as opposed to the scary page shown in Figure 12.2), you can make a simple modification in the Web.Config file to add your settings. Open Web.Config and modify the customErrors element, which normally looks like the following:

<customErrors mode="RemoteOnly" />

You can change it so any error that occurs will redirect to a specific page using the defaultRedirect attribute:

<customErrors mode="RemoteOnly" defaultRedirect="ErrorPage.aspx" />

You must create the page you're redirecting users to; that is, ErrorPage.aspx must be a page you've created in your application. To test this out in the sample application, ...

Get ASP.NET Developer's JumpStart 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.