分享

ASP.NET MVC 定于全局异常(Global.asax文件)

 修行的嘟嘟 2012-08-07

protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex=Server.GetLastError();
            if (ex is HttpException && ex.InnerException!=null)
                ex = ex.InnerException;
            if (ex is HttpUnhandledException && ex.InnerException != null)
                ex = ex.InnerException;

            Server.ClearError();
            Utility.JSUtil.Alert("操作失败!",ex);
            Utility.JSUtil.ExecuteScript("history.go(-1)");

            Response.StatusCode = 601;
            string msg = ex.Message;
            if (msg.Length > 250)
                msg = ex.Message.Substring(0, 250);
            Response.StatusDescription = msg;
            Response.Write("<script type=\"text/javascript\">");
            if (Utility.JSUtil.CurrentPage.Session == null)
                Response.Write("alert(\"请求失败!\\r\\n"
                    + ex.Message.Replace("\\","\\\\").Replace(")", "\\)")
                    + "\")");
            else
                Utility.JSUtil.RegisterScript(null);
            Response.Write("</script>");
        }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多