How do I use the page directive ErrorPage

T

Tony Johansson

Hello!

CustomerData.aspx

When I run a page I get an exception which is correct and understandable and
not what the question is about.
Some of the text from the exception message is the following
The DELETE statement conflicted with the REFERENCE constraint
"FK_Orders_Customers". The conflict occurred in database "Northwind", table
"dbo_Orders", column 'CustomerID'.
The statement has been terminated.

The question is that I just want to prevent to have the exception displayed
but insted test to redirect to have the ErrorPage.aspx to be executed when
an exception is thrown by adding the ErrorPage directive to the following
page directive in the CustomerData.aspx page. As you can see I have assigned
ErrorPage.aspx to the ErrorPage directive
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="CustomerData.aspx.cs" Inherits="_Default"
ErrorPage="ErrorPage.aspx" %>

According to the documentation should this work but the ugly exception
message is still displayed in the browser.

Is it necessary to make any changes in the web.config to make it work
perhaps ?
Does anyone have any suggestion what I might have missed ?

As a summary I just want to prevent to have the exception being displayed
and instead have the ErrorPage being displayed.


//Tony
 
P

Paul Shapiro

Sample in web.config:
<!--
The <customErrors> section enables configuration of what to do if/when an
unhandled error occurs
during the execution of a request. Specifically, it enables developers to
configure html error pages
to be displayed in place of a error stack trace.
Default mode="RemoteOnly" gives stack trace for localhost errors.
Optional mode="On" gives redirections even locally (good for testing).
Optional mode="Off" gives stack trace even for remote users (might be
necessary for debugging the live site).
-->
<customErrors mode="RemoteOnly"
defaultRedirect="~/Open/GenericErrorPage.htm">
<error statusCode="403" redirect="~/Open/NoAccess.htm" />
<error statusCode="404" redirect="~/Open/FileNotFound.htm" />
</customErrors>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top