Ejemplo n.º 1
0
        // Must load the value of the fragment and store it in the values collection
        public virtual void Init(ExceptionPageTemplateValues values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            string tmp = Value;

            if (tmp != null)
            {
                values.Add(Name, tmp);
                return;
            }

            tmp = FilePath;
            if (!String.IsNullOrEmpty(tmp))
            {
                values.Add(Name, LoadFile(tmp));
                return;
            }

            tmp = ResourceName;
            if (!String.IsNullOrEmpty(tmp))
            {
                values.Add(Name, LoadResource(tmp));
                return;
            }
        }
Ejemplo n.º 2
0
 void FillDefaultCustomErrorValues(ExceptionPageTemplateValues values)
 {
     values.Add(ExceptionPageTemplate.Template_PageTitleName, "Runtime Error");
     values.Add(ExceptionPageTemplate.Template_ExceptionTypeName, "Runtime Error");
     values.Add(ExceptionPageTemplate.Template_ExceptionMessageName, "A runtime error has occurred");
     values.Add(ExceptionPageTemplate.Template_DescriptionName, "An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed (for security reasons).");
     values.Add(ExceptionPageTemplate.Template_DetailsName, "To enable the details of this specific error message to be viewable, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".");
 }
Ejemplo n.º 3
0
        void FillDefaultErrorValues(bool showTrace, bool showExceptionType, Exception baseEx, ExceptionPageTemplateValues values)
        {
            if (baseEx == null)
            {
                baseEx = this;
            }

            values.Add(ExceptionPageTemplate.Template_PageTitleName, String.Format("Error{0}", http_code != 0 ? " " + http_code : String.Empty));
            values.Add(ExceptionPageTemplate.Template_ExceptionTypeName, showExceptionType ? baseEx.GetType().ToString() : "Runtime error");
            values.Add(ExceptionPageTemplate.Template_ExceptionMessageName, http_code == 404 ? "The resource cannot be found." : HtmlEncode(baseEx.Message));

            string tmp = http_code != 0 ? "HTTP " + http_code + "." : String.Empty;

            values.Add(ExceptionPageTemplate.Template_DescriptionName, tmp + (http_code == 404 ? ERROR_404_DESCRIPTION : HtmlEncode(Description)));

            if (!String.IsNullOrEmpty(resource_name))
            {
                values.Add(ExceptionPageTemplate.Template_DetailsName, "Requested URL: " + HtmlEncode(resource_name));
            }
            else if (http_code == 404)
            {
                values.Add(ExceptionPageTemplate.Template_DetailsName, "No virtual path information available.");
            }
            else if (baseEx is HttpException)
            {
                tmp = ((HttpException)baseEx).Description;
                values.Add(ExceptionPageTemplate.Template_DetailsName, !String.IsNullOrEmpty(tmp) ? HtmlEncode(tmp) : "Web exception occurred but no additional error description given.");
            }
            else
            {
                var sb = new StringBuilder("Non-web exception.");

                tmp = baseEx.Source;
                if (!String.IsNullOrEmpty(tmp))
                {
                    sb.AppendFormat(" Exception origin (name of application or object): {0}.", HtmlEncode(tmp));
                }
                tmp = baseEx.HelpLink;
                if (!String.IsNullOrEmpty(tmp))
                {
                    sb.AppendFormat(" Additional information is available at {0}", HtmlEncode(tmp));
                }

                values.Add(ExceptionPageTemplate.Template_DetailsName, sb.ToString());
            }

            if (showTrace)
            {
                string stackTrace = baseEx.StackTrace;
                if (!String.IsNullOrEmpty(stackTrace))
                {
                    values.Add(ExceptionPageTemplate.Template_StackTraceName, HtmlEncode(stackTrace));
                }
            }
        }
Ejemplo n.º 4
0
        public string GetHtmlErrorMessage()
        {
            var values = new ExceptionPageTemplateValues();
            ExceptionPageTemplate template = PageTemplate;

            try {
                values.Add(ExceptionPageTemplate.Template_RuntimeVersionInformationName, RuntimeHelpers.MonoVersion);
                values.Add(ExceptionPageTemplate.Template_AspNetVersionInformationName, Environment.Version.ToString());

                HttpContext ctx = HttpContext.Current;
                ExceptionPageTemplateType pageType = ExceptionPageTemplateType.Standard;

                if (ctx != null && ctx.IsCustomErrorEnabled)
                {
                    if (http_code != 404 && http_code != 403)
                    {
                        FillDefaultCustomErrorValues(values);
                        pageType = ExceptionPageTemplateType.CustomErrorDefault;
                    }
                    else
                    {
                        FillDefaultErrorValues(false, false, null, values);
                    }
                }
                else
                {
                    Exception ex = GetBaseException();
                    if (ex == null)
                    {
                        ex = this;
                    }

                    values.Add(ExceptionPageTemplate.Template_FullStackTraceName, FormatFullStackTrace());
                    HtmlizedException htmlException = ex as HtmlizedException;
                    if (htmlException == null)
                    {
                        FillDefaultErrorValues(true, true, ex, values);
                    }
                    else
                    {
                        pageType = ExceptionPageTemplateType.Htmlized;
                        FillHtmlizedErrorValues(values, htmlException, ref pageType);
                    }
                }

                return(template.Render(values, pageType));
            } catch (Exception ex) {
                Console.Error.WriteLine("An exception has occurred while generating HttpException page:");
                Console.Error.WriteLine(ex);
                Console.Error.WriteLine();
                Console.Error.WriteLine("The actual exception which was being reported was:");
                Console.Error.WriteLine(this);

                // we need the try/catch block in case the
                // problem was with MapPath, which will cause
                // IsCustomErrorEnabled to throw an exception
                try {
                    FillDefaultCustomErrorValues(values);
                    return(template.Render(values, ExceptionPageTemplateType.CustomErrorDefault));
                } catch {
                    return(DoubleFaultExceptionMessage);
                }
            }
        }
Ejemplo n.º 5
0
        void FillHtmlizedErrorValues(ExceptionPageTemplateValues values, HtmlizedException exc, ref ExceptionPageTemplateType pageType)
        {
            bool isParseException   = exc is ParseException;
            bool isCompileException = (!isParseException && exc is CompilationException);

            values.Add(ExceptionPageTemplate.Template_PageTitleName, HtmlEncode(exc.Title));
            values.Add(ExceptionPageTemplate.Template_DescriptionName, HtmlEncode(exc.Description));
            values.Add(ExceptionPageTemplate.Template_StackTraceName, HtmlEncode(exc.StackTrace));
            values.Add(ExceptionPageTemplate.Template_ExceptionTypeName, exc.GetType().ToString());
            values.Add(ExceptionPageTemplate.Template_ExceptionMessageName, HtmlEncode(exc.Message));
            values.Add(ExceptionPageTemplate.Template_DetailsName, HtmlEncode(exc.ErrorMessage));

            string origin;

            if (isParseException)
            {
                origin = "Parser";
            }
            else if (isCompileException)
            {
                origin = "Compiler";
            }
            else
            {
                origin = "Other";
            }
            values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionOriginName, origin);
            if (exc.FileText != null)
            {
                pageType |= ExceptionPageTemplateType.SourceError;
                StringBuilder shortSource = new StringBuilder();
                StringBuilder longSource;

                if (isCompileException)
                {
                    longSource = new StringBuilder();
                }
                else
                {
                    longSource = null;
                }
                FormatSource(shortSource, longSource, exc);
                values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionShortSourceName, shortSource.ToString());
                values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionLongSourceName, longSource != null ? longSource.ToString() : null);

                if (exc.SourceFile != exc.FileName)
                {
                    values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionSourceFileName, FormatSourceFile(exc.SourceFile));
                }
                else
                {
                    values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionSourceFileName, FormatSourceFile(exc.FileName));
                }
                if (isParseException || isCompileException)
                {
                    int[] errorLines = exc.ErrorLines;
                    int   numErrors  = errorLines != null ? errorLines.Length : 0;
                    var   lines      = new StringBuilder();
                    for (int i = 0; i < numErrors; i++)
                    {
                        if (i > 0)
                        {
                            lines.Append(", ");
                        }
                        lines.Append(errorLines [i]);
                    }
                    values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionErrorLinesName, lines.ToString());
                }
            }
            else
            {
                values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionSourceFileName, FormatSourceFile(exc.FileName));
            }

            if (isCompileException)
            {
                CompilationException cex    = exc as CompilationException;
                StringCollection     output = cex.CompilerOutput;

                if (output != null && output.Count > 0)
                {
                    pageType |= ExceptionPageTemplateType.CompilerOutput;
                    var  sb    = new StringBuilder();
                    bool first = true;
                    foreach (string s in output)
                    {
                        sb.Append(HtmlEncode(s));
                        if (first)
                        {
                            sb.Append("<br/>");
                            first = false;
                        }
                        sb.Append("<br/>");
                    }

                    values.Add(ExceptionPageTemplate.Template_HtmlizedExceptionCompilerOutputName, sb.ToString());
                }
            }
        }
Ejemplo n.º 6
0
		// Must load the value of the fragment and store it in the values collection
		public virtual void Init (ExceptionPageTemplateValues values)
		{
			if (values == null)
				throw new ArgumentNullException ("values");

			string tmp = Value;
			if (tmp != null) {
				values.Add (Name, tmp);
				return;
			}

			tmp = FilePath;
			if (!String.IsNullOrEmpty (tmp)) {
				values.Add (Name, LoadFile (tmp));
				return;
			}

			tmp = ResourceName;
			if (!String.IsNullOrEmpty (tmp)) {
				values.Add (Name, LoadResource (tmp));
				return;
			}
		}
Ejemplo n.º 7
0
		void FillDefaultErrorValues (bool showTrace, bool showExceptionType, Exception baseEx, ExceptionPageTemplateValues values)
		{
			if (baseEx == null)
				baseEx = this;
			
			values.Add (ExceptionPageTemplate.Template_PageTitleName, String.Format ("Error{0}", http_code != 0 ? " " + http_code : String.Empty));
			values.Add (ExceptionPageTemplate.Template_ExceptionTypeName, showExceptionType ? baseEx.GetType ().ToString () : "Runtime error");
			values.Add (ExceptionPageTemplate.Template_ExceptionMessageName, http_code == 404 ? "The resource cannot be found." : HtmlEncode (baseEx.Message));

			string tmp = http_code != 0 ? "HTTP " + http_code + "." : String.Empty;
			values.Add (ExceptionPageTemplate.Template_DescriptionName, tmp + (http_code == 404 ? ERROR_404_DESCRIPTION : HtmlEncode (Description)));

			if (!String.IsNullOrEmpty (resource_name))
				values.Add (ExceptionPageTemplate.Template_DetailsName, "Requested URL: " + HtmlEncode (resource_name));
			else if (http_code == 404)
				values.Add (ExceptionPageTemplate.Template_DetailsName, "No virtual path information available.");
			else if (baseEx is HttpException) {
				tmp = ((HttpException)baseEx).Description;
				values.Add (ExceptionPageTemplate.Template_DetailsName, !String.IsNullOrEmpty (tmp) ? HtmlEncode (tmp) : "Web exception occurred but no additional error description given.");
			} else {
				var sb = new StringBuilder ("Non-web exception.");

				tmp = baseEx.Source;
				if (!String.IsNullOrEmpty (tmp))
					sb.AppendFormat (" Exception origin (name of application or object): {0}.", HtmlEncode (tmp));
				tmp = baseEx.HelpLink;
				if (!String.IsNullOrEmpty (tmp))
					sb.AppendFormat (" Additional information is available at {0}", HtmlEncode (tmp));
				
				values.Add (ExceptionPageTemplate.Template_DetailsName, sb.ToString ());
			}
			
			if (showTrace) {
				string stackTrace = baseEx.StackTrace;
				if (!String.IsNullOrEmpty (stackTrace))
					values.Add (ExceptionPageTemplate.Template_StackTraceName, HtmlEncode (stackTrace));
			}
		}
Ejemplo n.º 8
0
		void FillDefaultCustomErrorValues (ExceptionPageTemplateValues values)
		{
			values.Add (ExceptionPageTemplate.Template_PageTitleName, "Runtime Error");
			values.Add (ExceptionPageTemplate.Template_ExceptionTypeName, "Runtime Error");
			values.Add (ExceptionPageTemplate.Template_ExceptionMessageName, "A runtime error has occurred");
			values.Add (ExceptionPageTemplate.Template_DescriptionName, "An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed (for security reasons).");
			values.Add (ExceptionPageTemplate.Template_DetailsName, "To enable the details of this specific error message to be viewable, please create a &lt;customErrors&gt; tag within a &quot;web.config&quot; configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its &quot;mode&quot; attribute set to &quot;Off&quot;.");
		}
Ejemplo n.º 9
0
		void FillHtmlizedErrorValues (ExceptionPageTemplateValues values, HtmlizedException exc, ref ExceptionPageTemplateType pageType)
		{
			bool isParseException = exc is ParseException;
			bool isCompileException = (!isParseException && exc is CompilationException);
			values.Add (ExceptionPageTemplate.Template_PageTitleName, HtmlEncode (exc.Title));
			values.Add (ExceptionPageTemplate.Template_DescriptionName, HtmlEncode (exc.Description));
			values.Add (ExceptionPageTemplate.Template_StackTraceName, HtmlEncode (exc.StackTrace));
			values.Add (ExceptionPageTemplate.Template_ExceptionTypeName, exc.GetType ().ToString ());
			values.Add (ExceptionPageTemplate.Template_ExceptionMessageName, HtmlEncode (exc.Message));
			values.Add (ExceptionPageTemplate.Template_DetailsName, HtmlEncode (exc.ErrorMessage));

			string origin;
			if (isParseException)
				origin = "Parser";
			else if (isCompileException)
				origin = "Compiler";
			else
				origin = "Other";
			values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionOriginName, origin);
			if (exc.FileText != null) {
				pageType |= ExceptionPageTemplateType.SourceError;
				StringBuilder shortSource = new StringBuilder ();
				StringBuilder longSource;
				
				if (isCompileException)
					longSource = new StringBuilder ();
				else
					longSource = null;
				FormatSource (shortSource, longSource, exc);
				values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionShortSourceName, shortSource.ToString ());
				values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionLongSourceName, longSource != null ? longSource.ToString () : null);
				
				if (exc.SourceFile != exc.FileName)
					values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionSourceFileName, FormatSourceFile (exc.SourceFile));
				else
					values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionSourceFileName, FormatSourceFile (exc.FileName));
				if (isParseException || isCompileException) {
					int[] errorLines = exc.ErrorLines;
					int numErrors = errorLines != null ? errorLines.Length : 0;
					var lines = new StringBuilder ();
					for (int i = 0; i < numErrors; i++) {
						if (i > 0)
							lines.Append (", ");
						lines.Append (errorLines [i]);
					}
					values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionErrorLinesName, lines.ToString ());
				}
			} else
				values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionSourceFileName, FormatSourceFile (exc.FileName));

			if (isCompileException) {
				CompilationException cex = exc as CompilationException;
				StringCollection output = cex.CompilerOutput;

				if (output != null && output.Count > 0) {
					pageType |= ExceptionPageTemplateType.CompilerOutput;
					var sb = new StringBuilder ();
					bool first = true;
					foreach (string s in output) {
						sb.Append (HtmlEncode (s));
						if (first) {
							sb.Append ("<br/>");
							first = false;
						}
						sb.Append ("<br/>");
					}
					
					values.Add (ExceptionPageTemplate.Template_HtmlizedExceptionCompilerOutputName, sb.ToString ());
				}
			}
		}
Ejemplo n.º 10
0
		public string GetHtmlErrorMessage ()
		{
			var values = new ExceptionPageTemplateValues ();
			ExceptionPageTemplate template = PageTemplate;

			try {
				values.Add (ExceptionPageTemplate.Template_RuntimeVersionInformationName, RuntimeHelpers.MonoVersion);
				values.Add (ExceptionPageTemplate.Template_AspNetVersionInformationName, Environment.Version.ToString ());
				
				HttpContext ctx = HttpContext.Current;
				ExceptionPageTemplateType pageType = ExceptionPageTemplateType.Standard;

				if (ctx != null && ctx.IsCustomErrorEnabled) {
					if (http_code != 404 && http_code != 403) {
						FillDefaultCustomErrorValues (values);
						pageType = ExceptionPageTemplateType.CustomErrorDefault;
					} else
						FillDefaultErrorValues (false, false, null, values);
				} else {
					Exception ex = GetBaseException ();
					if (ex == null)
						ex = this;

					values.Add (ExceptionPageTemplate.Template_FullStackTraceName, FormatFullStackTrace ());
					HtmlizedException htmlException = ex as HtmlizedException;
					if (htmlException == null)
						FillDefaultErrorValues (true, true, ex, values);
					else {
						pageType = ExceptionPageTemplateType.Htmlized;
						FillHtmlizedErrorValues (values, htmlException, ref pageType);
					}
				}
				
				return template.Render (values, pageType);
			} catch (Exception ex) {
				Console.Error.WriteLine ("An exception has occurred while generating HttpException page:");
				Console.Error.WriteLine (ex);
				Console.Error.WriteLine ();
				Console.Error.WriteLine ("The actual exception which was being reported was:");
				Console.Error.WriteLine (this);

				// we need the try/catch block in case the
				// problem was with MapPath, which will cause
				// IsCustomErrorEnabled to throw an exception
				try {
					FillDefaultCustomErrorValues (values);
					return template.Render (values, ExceptionPageTemplateType.CustomErrorDefault);
				} catch {
					return DoubleFaultExceptionMessage;
				}
			}
		}