A simple error-handling page can be set by web.config.
Copy Code code 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 programmatically present the cause of the error, you can do it by page_error the event.
Another way can be achieved by Global.asax, which I think is more convenient, and if you can combine a separate and friendlier page, it seems more comfortable:
Global.asax (Error log can be logged if required)
Copy Code code as follows:
void Application_Error (object sender, EventArgs e)
{
Exception objerr = Server.GetLastError (). GetBaseException ();
String error = "Exception page occurred:" + Request.Url.ToString () + "<br>";
Error + + "Exception information:" + objerr.message + "<br>";
Server.ClearError ();
application["Error"] = error;
Response.Redirect ("~/errorpage/errorpage.aspx");
}
Errorpage.aspx
protected void Page_Load (object sender, EventArgs e)
{
Errormessagelabel.text = application["Error"]. ToString ();
}
When the end user uses the application, they may not want to know the cause of the error, and this time we can do it through the checkbox to see if the cause of the error is present. You can place the label in a Div, and then use the check box to decide whether to render the div.
Copy Code code as follows:
<script language= "javascript" type= "Text/javascript" >
<!-- Br>function Checkerror_onclick () {
var chk = document.getElementById ("CheckError");
var diverror = document.getElementById ("errormsg");
if (chk.checked)
{
DivError.style.display = "inline";
}
Else
{
DivError.style.display = "None";
}
//-->
</script>