How to asp.net the error prompt page when an exception or error occurs
How do we handle the error message page when an exception or error occurs in asp.net?
I have summed up the following ways:
I: Using the method Response.Redirect ()
Look at the following 2 pieces of code:
1.
When an exception occurs in the page admin.aspx
Try
{//
program logic
}
catch (OverflowException)
{//The exception that is
thrown when an arithmetic operation, type conversion, or conversion operation in the selected context causes an overflow
/ /For example: MinValue or greater than int maxvalue, exception, go to error page
Response.Redirect ("errorpage.aspx", True);
}
2.
In the open source project asp.net startkit timetracker
A logical error occurred in the page userlist.aspx
if (Ttsecurity.isinrole (ttuser.userroleadministrator) = = False)
{
//The role of the visitor is not "Administrator", the Prompt Role error page
Response.Redirect ("Accessdenied.aspx?") Index=-1 ", True);
}
Ii. using the configuration file Web.config
We first set
<customerrors
mode= "on"
defaultredirect= "errorpage.aspx"
/>