Application_Error在生产服务器中不起作用

时间:2015-04-27 06:15:07

标签: asp.net iis

Application_Error未在生产服务器上触发。但它在我们的本地服务器和其他亚马逊服务器上工作。在我们的本地服务器上有windows7操作系统和IIS(7.5)版本,但生产服务器有Windows8和IIS(8+)版本。任何人都有任何想法。

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
      Exception  ex = Server.GetLastError().GetBaseException();

      string cls = ex.TargetSite.DeclaringType.Name;
      string mtd = ex.TargetSite.Name;

        string ErrorMessage = ex.Message;
        string page = Request.Path;
        string url = Request.PhysicalPath;
        string StackTrace = "";
        string inputdata = "";


        if (ErrorMessage != "File does not exist.")
        {
             StackTrace = ex.StackTrace;
             foreach (string i in Session.Contents)
             {
                 if (Session[i] != null)
                 {
                     if (inputdata != "")
                     {
                         inputdata = inputdata + " , [" + i + "] = " + Session[i].ToString();
                     }
                     else
                     {
                         inputdata = "[" + i + "] = " + Session[i].ToString();
                     }
                 }
             }

            string flg = objBus.insertException(page, "", ErrorMessage, StackTrace, "", url, Session["UserID"].ToString(), inputdata,"");
            //string flg = "0";


            //Response.Redirect("~/ErrorPage.aspx?errorId=" + flg, false);
            Server.Transfer("~/ErrorPage.aspx?errorId=" + flg, false);
        }


    }

1 个答案:

答案 0 :(得分:-2)

发布时,尝试启用“发布期间预编译”,这应在发布文件夹中包含PrecompiledApp.config