在程序中写入:throw new Exception("error");这样的代码,我现在想在发生异常的时候跳转到指定的页面,比如跳转到Error.aspx页面,并在此页面上显示错误的消息???

解决方案 »

  1.   

    try
    {
    ........
    throw new Exception("error"); 
    }
    catch
    {
         //这里转Error.aspx页面
    }
      

  2.   

    页面级的处理(Page_Error)不做的话 
    可以在Global.asax 文件里的Application_Error事件中进行处理然后传错误信息并跳转到Error.aspx页面
      

  3.   

    void Page_Error(Object sender, EventArgs e) {
                    Response.Redirect(...);
            Server.ClearError();
        }在Page_Error里也可以处理啊
      

  4.   

    try
    {
    ........
    throw new Exception("error");
    }
    catch
    {
        //这里转Error.aspx页面

      

  5.   


    void Application_Error(object sender, EventArgs e) 
        { 
            Exception objErr = Server.GetLastError().GetBaseException();
            string error = "page: " + Request.Url.ToString() + "<br>";
            error += "message: " + objErr.Message + "<br>";
            error += "detail: <pre>" + objErr.ToString() + "</pre>";
            Server.ClearError();
            Application["errorMsg"] = error;
            Response.Redirect("~/ErrorPage/ErrorPage.aspx");     }
    ErrorPage.aspx 
     try
                {
                    string errorMsg = Application["errorMsg"].ToString();
                    string errorFile = errorMsg.Substring(0, errorMsg.IndexOf("<br>message:"));                clsCommon.WriteErrorLog(errorFile, "", Request.UserHostAddress + ":" + Request.UserHostName + ":" + Request.UrlReferrer, errorMsg, UserID);                this.Label1.Text = errorMsg.Substring(0, errorMsg.IndexOf("<br>detail:"));
                }
                catch (Exception)
                {                throw;
                }
      

  6.   


    或重写Page中的OnError方法