1. New Golbal.asax
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");
}
2. Front section:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "ErrorPage.aspx.cs" inherits= "ErrorPage"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>ErrorPage</title>
<script language= "javascript" type= "Text/javascript" >
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>
<body>
<form id= "Form1" runat= "Server" >
<div style= "Text-align:center" >
<asp:label id= "Label1" runat= "Server" text= "page is Wrong" style= "Text-align:center" ></asp:Label><br/>
<input type= "checkbox" id= "CheckError" onclick= "Checkerror_onclick ()"/> View detailed information <br/><br/>
</div>
<div id= "errormsg" style= "text-align:center; Display:none "runat=" Server >
<asp:label id= "Errormessagelabel" runat= "Server" text= "></asp:label><br/>
</div>
</form>
</body>
3. Background error message display:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
Errormessagelabel.text = application["Error"]. ToString ();
}