protected void Page_Error(object sender, EventArgs e)
{
string errorMsg = String.Empty;
Exception currentError = Server.GetLastError();
errorMsg += "来自页面的异常处理<br />";
errorMsg += "系统发生错误:<br />";
errorMsg += "错误地址:" + Request.Url + "<br />";
errorMsg += "错误信息:" + currentError.Message + "<br />";
string html = "<link href=\"/CSS/bootstrap-3.3.7/css/bootstrap.min.css\" rel=\"stylesheet\" /><div class=\"panel panel-danger\" style=\"width:90%;margin:20px auto\"><div class=\"panel-heading\">出错了!</div> <div class=\"panel-body\"> <div class=\"alert alert-danger\" role=\"alert\" style=\"text-align: left\">";
html += errorMsg;
html += "<a href=\" / \" target='parent'>[回首页]</a> </ div > </ div > </ div > ";
Response.Write(html);
Server.ClearError();//清除异常(否则将引发全局的Application_Error事件)
}