Exemplo n.º 1
0
        /// <include file='doc\HttpException.uex' path='docs/doc[@for="HttpException.GetHtmlErrorMessage"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public string GetHtmlErrorMessage()
        {
            ErrorFormatter formatter = GetErrorFormatter(this);

            if (formatter == null)
            {
                return(null);
            }
            return(formatter.GetHtmlErrorMessage());
        }
Exemplo n.º 2
0
        /*
         * Return the formatter associated with this exception
         */
        internal static ErrorFormatter GetErrorFormatter(Exception e)
        {
            Exception      inner           = e.InnerException;
            ErrorFormatter nestedFormatter = null;

            // First, see if the inner exception has a formatter
            if (inner != null)
            {
                nestedFormatter = GetErrorFormatter(inner);
                if (nestedFormatter != null)
                {
                    return(nestedFormatter);
                }

                if (inner is ConfigurationException)
                {
                    ConfigurationException ce = inner as ConfigurationException;
                    if (ce != null && ce.Filename != null)
                    {
                        nestedFormatter = new ConfigErrorFormatter((ConfigurationException)inner);
                    }
                }
                else if (inner is SecurityException)
                {
                    nestedFormatter = new SecurityErrorFormatter(inner);
                }
            }

            // If it does, return it rather than our own
            if (nestedFormatter != null)
            {
                return(nestedFormatter);
            }

            HttpException httpExc = e as HttpException;

            if (httpExc != null)
            {
                return(httpExc._errorFormatter);
            }

            return(null);
        }
        internal static ErrorFormatter GetErrorFormatter(Exception e)
        {
            Exception      innerException = e.InnerException;
            ErrorFormatter errorFormatter = null;

            if (innerException != null)
            {
                errorFormatter = GetErrorFormatter(innerException);
                if (errorFormatter != null)
                {
                    return(errorFormatter);
                }
                if (innerException is ConfigurationException)
                {
                    ConfigurationException exception2 = innerException as ConfigurationException;
                    if ((exception2 != null) && (exception2.Filename != null))
                    {
                        errorFormatter = new ConfigErrorFormatter((ConfigurationException)innerException);
                    }
                }
                else if (innerException is SecurityException)
                {
                    errorFormatter = new SecurityErrorFormatter(innerException);
                }
            }
            if (errorFormatter != null)
            {
                return(errorFormatter);
            }
            HttpException exception3 = e as HttpException;

            if (exception3 != null)
            {
                return(exception3._errorFormatter);
            }
            return(null);
        }
Exemplo n.º 4
0
        internal static string GetSourceFileLines(string fileName, Encoding encoding, string sourceCode, int lineNumber)
        {
            if ((fileName != null) && !HttpRuntime.HasFilePermission(fileName))
            {
                return(System.Web.SR.GetString("WithFile_No_Relevant_Line"));
            }
            StringBuilder builder = new StringBuilder();

            if (lineNumber <= 0)
            {
                return(System.Web.SR.GetString("WithFile_No_Relevant_Line"));
            }
            TextReader reader = null;
            string     virtualPathFromHttpLinePragma = ErrorFormatter.GetVirtualPathFromHttpLinePragma(fileName);

            if (virtualPathFromHttpLinePragma != null)
            {
                Stream stream = VirtualPathProvider.OpenFile(virtualPathFromHttpLinePragma);
                if (stream != null)
                {
                    reader = Util.ReaderFromStream(stream, System.Web.VirtualPath.Create(virtualPathFromHttpLinePragma));
                }
            }
            try
            {
                if ((reader == null) && (fileName != null))
                {
                    reader = new StreamReader(fileName, encoding, true, 0x1000);
                }
            }
            catch
            {
            }
            if (reader == null)
            {
                if (sourceCode == null)
                {
                    return(System.Web.SR.GetString("WithFile_No_Relevant_Line"));
                }
                reader = new StringReader(sourceCode);
            }
            try
            {
                string str2;
                bool   flag = false;
                if (ErrorFormatter.IsTextRightToLeft)
                {
                    builder.Append("<div dir=\"ltr\">");
                }
                int num = 1;
Label_0098:
                str2 = reader.ReadLine();
                if (str2 != null)
                {
                    if (num == lineNumber)
                    {
                        builder.Append("<font color=red>");
                    }
                    if ((num >= (lineNumber - 2)) && (num <= (lineNumber + 2)))
                    {
                        flag = true;
                        string str3 = num.ToString("G", CultureInfo.CurrentCulture);
                        builder.Append(System.Web.SR.GetString("WithFile_Line_Num", new object[] { str3 }));
                        if (str3.Length < 3)
                        {
                            builder.Append(' ', 3 - str3.Length);
                        }
                        builder.Append(HttpUtility.HtmlEncode(str2));
                        if (num != (lineNumber + 2))
                        {
                            builder.Append("\r\n");
                        }
                    }
                    if (num == lineNumber)
                    {
                        builder.Append("</font>");
                    }
                    if (num <= (lineNumber + 2))
                    {
                        num++;
                        goto Label_0098;
                    }
                }
                if (ErrorFormatter.IsTextRightToLeft)
                {
                    builder.Append("</div>");
                }
                if (!flag)
                {
                    return(System.Web.SR.GetString("WithFile_No_Relevant_Line"));
                }
            }
            finally
            {
                reader.Close();
            }
            return(builder.ToString());
        }
Exemplo n.º 5
0
 internal void SetFormatter(ErrorFormatter errorFormatter) {
     _errorFormatter = errorFormatter;
 }
 internal void SetOverrideErrorFormatter(ErrorFormatter errorFormatter)
 {
     this._overrideErrorFormatter = errorFormatter;
 }
Exemplo n.º 7
0
 internal void SetFormatter(ErrorFormatter errorFormatter)
 {
     _errorFormatter = errorFormatter;
 }