예제 #1
0
        /// <summary>
        /// 缺省的错误处理
        /// </summary>
        /// <param name="e">事件参数</param>
        /// <remarks>
        /// 重写了系统的OnError方法。首先清除了出错前输出的部分,
        /// 然后从资源中得到正确的错误信息并做一些相应的转义,
        /// 最后转到错误页面输出错误信息结束。
        /// </remarks>
        protected override void OnError(EventArgs e)
        {
            Response.Clear();                                                                                                   //清除已经输出的部分,然后转到错误页面
            string strHtml = CommonDefine.GetEmbeddedResString(CommonResource.ErrorTemplate);

            System.Exception ex = Server.GetLastError();                                        //得到错误信息

            if (ex != null)
            {
                TransExceptionInfo tei = new TransExceptionInfo(ex);

                string strStackTrace = string.Empty;

                if ((ex is System.ApplicationException == false) || IsOutputStackTrace())
                {
                    strStackTrace = Server.HtmlEncode(tei.StackTrace);
                }
                //					strStackTrace = UrlEncodeToGB2312(tei.StackTrace);

                //				string strMsg = Server.HtmlEncode(tei.Message);//changed by ccic\yuanyong 2005-7-28
                string strMsg = tei.Message;                //changed by ccic\yuanyong 2005-7-28
                //				string strMsg = UrlEncodeToGB2312(tei.Message);

                if (tei.SupportHtml != string.Empty)
                {
                    strMsg += "<p>" + tei.SupportHtml + "<p>";
                }

                strStackTrace = Server.HtmlEncode(strStackTrace);

                string strMsgEncoding        = strMsg.Replace("\n", "<br>");
                string strStackTraceEncoding = strStackTrace.Replace("\n", "<br>");

                strHtml = strHtml.Replace("{LabelError}", strMsgEncoding);
                strHtml = strHtml.Replace("{StackTrace}", strStackTraceEncoding);

                string url = BaseWebSection.GetConfig().ErrorImgUrl;
                if (string.IsNullOrEmpty(url))
                {
                    url = this.ClientScript.GetWebResourceUrl(typeof(WebBaseClass),
                                                              "MCS.Library.Accredit.WebBase.stopLogo.gif");
                }
                strHtml = strHtml.Replace("{ShowErrorImg}", url);

                Server.ClearError();

                Response.Write(strHtml);
                Response.End();
            }
        }
예제 #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="ex"></param>
        public TransExceptionInfo(System.Exception ex)
        {
            string strMsg = CommonDefine.GetSoapExceptionMessage(ex);

            if (ex is SqlException)
            {
                SqlException sqlException = (SqlException)ex;

                if (sqlException.Number == 7619)
                {
                    strMsg = "对不起!你输入的查询中有含糊的符号,或者全文检索服务出现问题。";
                }
            }
            else
            if (ex is System.TypeInitializationException || ex is System.Reflection.TargetInvocationException)
            {
                ex     = ex.InnerException;
                strMsg = HttpUtility.HtmlEncode(ex.Message);
            }

            _Message    = strMsg;
            _StackTrace = ex.StackTrace;
            _Exception  = ex;
        }