Beispiel #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();
            }
        }
Beispiel #2
0
        ///// <summary>
        ///// 根据系统配置信息数据获取指定文件类型(用于展示文件图标或者文件打开方式)
        ///// </summary>
        ///// <param name="strExt">文件的扩展名</param>
        ///// <returns>配置中对应的配置节点</returns>
        //private XmlElement GetFileTypeDespNode(string strExt)
        //{
        //    SysConfig sc = new SysConfig();

        //    XmlNode nodeFileType = sc.GetSectionNode("BaseWebClass", "FileType");

        //    XmlElement elemItem = null;

        //    if (nodeFileType != null)
        //    {
        //        strExt = strExt.ToUpper();

        //        foreach (XmlElement elem in nodeFileType.ChildNodes)
        //        {
        //            string strExtNames = elem.GetAttribute("fileExt").ToUpper();

        //            if (strExtNames.IndexOf(strExt) != -1)
        //            {
        //                elemItem = elem;
        //                break;
        //            }
        //        }
        //    }

        //    return elemItem;
        //}
        //		/// <summary>
        //		/// 字符串编码转换
        //		/// </summary>
        //		/// <param name="strText"></param>
        //		/// <returns></returns>
        //		private static string UrlEncodeToGB2312(string strText)
        //		{
        //			byte[] bytes = Encoding.GetEncoding("gb2312").GetBytes(strText);
        //
        //			return HttpUtility.UrlEncode(bytes);
        //		}

        #endregion

        #region protected
        /// <summary>
        /// 设置错误信息的Xml文本
        /// </summary>
        /// <param name="xmlResult">需要放置信息的Xml对象</param>
        /// <param name="ex">例外对象</param>
        protected virtual void SetErrorResult(XmlDocument xmlResult, System.Exception ex)
        {
            TransExceptionInfo tei = new TransExceptionInfo(ex);

            string strMsg = "<Message>" + HttpUtility.HtmlEncode(tei.Message) + "</Message>";

            if (tei.SupportHtml != string.Empty)
            {
                strMsg += "<SupportText>\n" + tei.SupportHtml + "</SupportText>";
            }

            if ((ex is System.ApplicationException) == false || IsOutputStackTrace())
            {
                strMsg += "\n" + "<MessageExt>" + HttpUtility.HtmlEncode(tei.StackTrace) + "</MessageExt>";
            }

            SetErrorResult(xmlResult, strMsg, tei.StackTrace);
        }
		/// <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();
			}
		}
		///// <summary>
		///// 根据系统配置信息数据获取指定文件类型(用于展示文件图标或者文件打开方式)
		///// </summary>
		///// <param name="strExt">文件的扩展名</param>
		///// <returns>配置中对应的配置节点</returns>
		//private XmlElement GetFileTypeDespNode(string strExt)
		//{
		//    SysConfig sc = new SysConfig();

		//    XmlNode nodeFileType = sc.GetSectionNode("BaseWebClass", "FileType");

		//    XmlElement elemItem = null;

		//    if (nodeFileType != null)
		//    {
		//        strExt = strExt.ToUpper();

		//        foreach (XmlElement elem in nodeFileType.ChildNodes)
		//        {
		//            string strExtNames = elem.GetAttribute("fileExt").ToUpper();

		//            if (strExtNames.IndexOf(strExt) != -1)
		//            {
		//                elemItem = elem;
		//                break;
		//            }
		//        }
		//    }

		//    return elemItem;
		//}
		//		/// <summary>
		//		/// 字符串编码转换
		//		/// </summary>
		//		/// <param name="strText"></param>
		//		/// <returns></returns>
		//		private static string UrlEncodeToGB2312(string strText)
		//		{
		//			byte[] bytes = Encoding.GetEncoding("gb2312").GetBytes(strText);
		//
		//			return HttpUtility.UrlEncode(bytes);
		//		}

		#endregion

		#region protected
		/// <summary>
		/// 设置错误信息的Xml文本
		/// </summary>
		/// <param name="xmlResult">需要放置信息的Xml对象</param>
		/// <param name="ex">例外对象</param>
		protected virtual void SetErrorResult(XmlDocument xmlResult, System.Exception ex)
		{
			TransExceptionInfo tei = new TransExceptionInfo(ex);

			string strMsg = "<Message>" + HttpUtility.HtmlEncode(tei.Message) + "</Message>";

			if (tei.SupportHtml != string.Empty)
				strMsg += "<SupportText>\n" + tei.SupportHtml + "</SupportText>";

			if ((ex is System.ApplicationException) == false || IsOutputStackTrace())
				strMsg += "\n" + "<MessageExt>" + HttpUtility.HtmlEncode(tei.StackTrace) + "</MessageExt>";

			SetErrorResult(xmlResult, strMsg, tei.StackTrace);
		}