System.Web.HttpException.GetHtmlErrorMessage C# (CSharp) Method

GetHtmlErrorMessage() public method

public GetHtmlErrorMessage ( ) : string
return string
		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;
				}
			}
		}

Usage Example

Example #1
0
        static void FinishWithException(HttpWorkerRequest wr, HttpException e)
        {
            int code = e.GetHttpCode();

            wr.SendStatus(code, HttpWorkerRequest.GetStatusDescription(code));
            wr.SendUnknownResponseHeader("Connection", "close");
            Encoding enc = Encoding.ASCII;

            wr.SendUnknownResponseHeader("Content-Type", "text/html; charset=" + enc.WebName);
            string msg = e.GetHtmlErrorMessage();

            byte [] contentBytes = enc.GetBytes(msg);
            wr.SendUnknownResponseHeader("Content-Length", contentBytes.Length.ToString());
            wr.SendResponseFromMemory(contentBytes, contentBytes.Length);
            wr.FlushResponse(true);
            wr.CloseConnection();
            HttpApplication.requests_total_counter.Increment();
        }
All Usage Examples Of System.Web.HttpException::GetHtmlErrorMessage