internal ErrorFormatter GetErrorFormatter(Exception e) {
            ErrorFormatter  errorFormatter = null;

            if (_overrideErrorFormatter != null) {
                return _overrideErrorFormatter;
            }

            // Try to get an error formatter
            errorFormatter = HttpException.GetErrorFormatter(e);

            if (errorFormatter == null) {
                ConfigurationException ce = e as ConfigurationException;
                if (ce != null && !String.IsNullOrEmpty(ce.Filename))
                    errorFormatter = new ConfigErrorFormatter(ce);
            }

            // If we couldn't get one, create one here
            if (errorFormatter == null) {
                // If it's a 404, use a special error page, otherwise, use a more
                // generic one.
                if (_statusCode == 404)
                    errorFormatter = new PageNotFoundErrorFormatter(Request.Path);
                else if (_statusCode == 403)
                    errorFormatter = new PageForbiddenErrorFormatter(Request.Path);
                else {
                    if (e is System.Security.SecurityException)
                        errorFormatter = new SecurityErrorFormatter(e);
                    else
                        errorFormatter = new UnhandledErrorFormatter(e);
                }
            }

            return errorFormatter;
        }
Ejemplo n.º 2
0
        internal ErrorFormatter GetErrorFormatter(Exception e) {
            ErrorFormatter  errorFormatter = null;

            if (_overrideErrorFormatter != null) {
                return _overrideErrorFormatter;
            }

            // Try to get an error formatter
            errorFormatter = HttpException.GetErrorFormatter(e);

            if (errorFormatter == null) {
                ConfigurationException ce = e as ConfigurationException;
                if (ce != null && !String.IsNullOrEmpty(ce.Filename))
                    errorFormatter = new ConfigErrorFormatter(ce);
            }

            // If we couldn't get one, create one here
            if (errorFormatter == null) {
                // If it's a 404, use a special error page, otherwise, use a more
                // generic one.
                if (_statusCode == 404)
                    errorFormatter = new PageNotFoundErrorFormatter(Request.Path);
                else if (_statusCode == 403)
                    errorFormatter = new PageForbiddenErrorFormatter(Request.Path);
                else {
                    if (e is System.Security.SecurityException)
                        errorFormatter = new SecurityErrorFormatter(e);
                    else
                        errorFormatter = new UnhandledErrorFormatter(e);
                }
            }

            // Show config source only on local request for security reasons
            // Config file snippet may unintentionally reveal sensitive information (not related to the error)
            ConfigErrorFormatter configErrorFormatter = errorFormatter as ConfigErrorFormatter;
            if (configErrorFormatter != null) {
                configErrorFormatter.AllowSourceCode = Request.IsLocal;
            }

            return errorFormatter;
        }