The simple error handling page can be set through web. config.
CopyCode The Code is as follows: <customerrors mode = "remoteonly" defaultredirect = "genericerrorpage.htm">
<Error statuscode = "403" Redirect = "noaccess.htm"/>
<Error statuscode = "404" Redirect = "filenotfound.htm"/>
</Customerrors>
If You Want to program the cause of an error, you can use the page_error event.
you can use global. I think this method is more convenient to implement with asax. In addition, it seems more comfortable to combine a separate and more friendly page:
global. asax (you can record error logs if needed) copy Code the code is as follows: void application_error (Object sender, eventargs e)
{< br> exception objerr = server. getlasterror (). getbaseexception ();
string error = "exception page:" + request. URL. tostring () + "
";
error + = "exception information:" + O Bjerr. Message + "
";
server. clearerror ();
application ["error"] = error;
response. Redirect ("~ /Errorpage. aspx ");
}< br> errorpage. aspx
protected void page_load (Object sender, eventargs e)
{< br> errormessagelabel. TEXT = application ["error"]. tostring ();
}
when end users use the Program , they may not want to know the cause of the error, you can use the check box to check whether the cause of the error is displayed. You can place the label in a div and use the check box to determine whether to render the div. copy Code the code is as follows: