Global.asax
void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 Exception objErr = Server.GetLastError().GetBaseException(); string error = "发生异常页: " + Request.Url.ToString() + ""; error += "<br/>异常信息: " + objErr.Message + ""; Server.ClearError(); Application["error"] = error; Response.Redirect("~/Common/error.aspx"); }
common/error.aspx
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { this.Literal1.Text = Request.QueryString["msg"].ToString(); } catch (Exception) { //throw; Literal1.Text = Application["error"].ToString(); } //Literal1.Text = Application["error"].ToString(); } }