excerpt from the cnblogs fantasy soft article:
1,webconfig Settings
<?xml version= "1.0"?>
<configuration>
<system.web>
<customerrors mode= "on" defaultredirect= "genericerrorpage.htm" >
<error statuscode= "403" redirect= "error403.htm"/>
<error statuscode= "404" redirect= "error404.htm"/>
</customErrors>
</system.web>
</configuration>
2,global.asax Settings
protected void Application_Error (object sender, EventArgs e) {
Exception objerr = Server.GetLastError (). GetBaseException ();
Response.Write ("Error:" + objerr.message);
Server.ClearError ();
}
3, using the ErrorPage property
<script language= "C #" runat= "Server" >
protected void Page_Load (object sender, EventArgs e) {
This. ErrorPage = "errorpage.htm";
}
</script>
4, using the Page_Error event handling method
protected void Page_Error (object sender, EventArgs e) {
Exception objerr = Server.GetLastError (). GetBaseException ();
Response.Write ("Error:" + objerr.message);
Server.ClearError (); Also pay attention to the use of this Code
}
sort by priority from highest to lowest: Page_Error Event-handling Methods > ErrorPage Properties > Application_Error Event-handling methods > <customErrors> configuration Items.