Web Applications Program After the release, in order to give the user a friendly interface and user experience, the user will jump to a custom error page when an error occurs, rather than the detailed exception list exposed to the user by Asp.net.
The simple error handling page can be set through web. config. < 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 the error, you can use the page_error event.
The other method can be implemented through global. asax. I think this method is more convenient. In addition, it seems more comfortable to combine a separate and more friendly page.
Global. asax (you can record the error log if necessary)
Void Application_error ( Object Sender, eventargs E)
{
Exception objerr = Server. getlasterror (). getbaseexception ();
String Error = " Exception page: " + Request. url. tostring () + " <Br> " ;
Error + = " Exception information: " + Objerr. Message + " <Br> " ;
Server. clearerror ();
Application [ " Error " ] = Error;
Response. Redirect ( " ~ /Errorpage. aspx " );
}
Errorpage. aspx
Protected Void Page_load ( Object Sender, eventargs E)
{
Errormessagelabel. Text=Application ["Error"]. Tostring ();
}