或許你可以利用Server.Transfer移轉到特定頁面。
下列程式碼示範擷取到錯誤之後移轉到ExceptionCaptureDemo.aspx。
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
Response.Write(ex.Message + "<br/>");
Server.Transfer("ExceptionCaptureDemo.aspx");
}
接著在ExceptionCaptureDemo.aspx就可以進行Exception的處理。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class ExceptionCaptureDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
Response.Write(ex.Message);
}
}
}
處理完之後記得呼叫Server.GetLastError()。
以上說明若有錯誤請指教,謝謝。
http://www.dotblogs.com.tw/terrychuang/