1.新建Golbal.asax
代碼如下:
void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string error = "發(fā)生異常頁: " + Request.Url.ToString() + "<br>";
error += "異常信息: " + objErr.Message + "<br>";
Server.ClearError();
Application["error"] = error;
Response.Redirect("~/ErrorPage/ErrorPage.aspx");
}
2.前臺部分:
代碼如下:
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<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>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<asp:Label ID="Label1" runat="server" Text="頁面出錯了" Style="text-align: center"></asp:Label><br/>
<input type="checkbox" id="CheckError" onclick="CheckError_onclick()" />查看詳細(xì)信息<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>
</html>
3.后臺把錯誤信息顯示:
代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
ErrorMessageLabel.Text = Application["error"].ToString();
}
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com