1 頁面的Error事件
private void WebForm1_Error(object sender, System.EventArgs e)
...{
Response.Write(Server.GetLastError().Message);
Server.ClearError();
}
2 Global.asax.cs裡的Application_Error事件
protected void Application_Error(Object sender, EventArgs e)
...{
Response.Redirect("Error.aspx?msg=" + Server.GetLastError().Message);
Server.ClearError();
}
Request.QueryString的用法
3 web.config中的<customErrors mode="RemoteOnly"/>
<!-- 自訂錯誤資訊
設定 customErrors mode="On" 或 "RemoteOnly" 以啟用自訂錯誤資訊,或設定為 "Off" 以禁用自訂錯誤資訊。
為每個要處理的錯誤添加 <error> 標記。
"On" 始終顯示自訂(友好的)資訊。
"Off" 始終顯示詳細的 ASP.NET 錯誤資訊。
"RemoteOnly" 只對不在本地 Web 服務器上啟動並執行
使用者顯示自訂(友好的)資訊。出於安全目的,建議使用此設定,以便
不向遠程用戶端顯示應用程式的詳細資料。
-->
<customErrors mode="On" defaultRedirect="Error.aspx"> 設定defaultRedirect 需要將mode設定為On
<customErrors mode="On" defaultRedirect="Error.aspx">
<error statusCode="404" redirect="Error.aspx?msg=你所訪問的頁面不存在或已被刪除"/>
</customErrors>
4 Document的屬性trace頁層級跟蹤
private void btnTest_Click(object sender, System.EventArgs e)
...{
this.Trace.Write("btnTest_Click","變數的值");
}
private void chk_CheckedChanged(object sender, System.EventArgs e)
...{
this.Trace.Warn("chk_CheckedChanged","CheckedChanged");//顯示紅色
}
TraceMode="SortByTime"或者"SortByCategory" //Category種類