コード例 #1
0
        // TODO setup ReturnUrl
        // For this every link to potentially forbidden should contain returnUrl parameter
        // one option to get it is HttpContext.Request.GetDisplayUrl();
        void Prepare()
        {
            var routineFeature   = this.HttpContext.Features.Get <AspRoutineFeature>();
            var exceptionHandler = this.HttpContext.Features.Get <IExceptionHandlerFeature>();
            var exception        = exceptionHandler?.Error;

            if (exception != null && routineFeature == null)
            {
                var markdown = InjectedManager.Markdown(exception);
                var correlationTokenRequest = this.HttpContext.Request.Headers["X-CorrelationToken"].FirstOrDefault();
                Guid.TryParse(correlationTokenRequest, out var correlationToken);

                //TODO add internal authorization log ?
                //applicationSettings.UnhandledExceptionLogger.TraceError(correlationToken, markdown);
            }

            RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

            Message = "Access denied. Ask network administrator to promote your user account.";
            Title   = "Security";

            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (environment == "Development")
            {
                ShowAdvancedInformation = true;
            }
            else
            {
                var isAdminPrivilege = false; // TODO: add this privilege through config file to the users with specific names
                if (isAdminPrivilege)
                {
                    ShowAdvancedInformation = true;
                }
            }
            if (ShowAdvancedInformation)
            {
                if (routineFeature != null && routineFeature.TraceDocument != null)
                {
                    var text = routineFeature.TraceDocument.Build();
                    ExceptionHtml = InjectedManager.ToHtml(text);
                }
                else if (exception != null)
                {
                    ExceptionHtml = InjectedManager.ToHtml(exception);
                }
                if (routineFeature != null)
                {
                    CorrelationToken = routineFeature.CorrelationToken.ToString();
                }
            }
        }
コード例 #2
0
        //public static bool FindSqlException(AggregateException aggregateException, out SqlException sqlException)
        //{
        //    sqlException = null;
        //    foreach (var ex in aggregateException.InnerExceptions)
        //    {
        //        if (ex is SqlException)
        //        {
        //            sqlException = (SqlException)ex;
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        void Prepare()
        {
            var exceptionHandler   = this.HttpContext.Features.Get <IExceptionHandlerFeature>();
            var aspRoutineFeature  = this.HttpContext.Features.Get <AspRoutineFeature>();
            var pageRoutineFeature = this.HttpContext.Features.Get <PageRoutineFeature>();

            // TODO: create url tree (where to go on error) and url to title (button name) map
            if (pageRoutineFeature != null)
            {
                ReturnUrl = pageRoutineFeature.Referrer;
            }

            var    unhandledException  = exceptionHandler?.Error;
            string detailsMarkdown     = default;
            var    isHandledByDocument = aspRoutineFeature != null && aspRoutineFeature.TraceDocument.IsExceptionHandled;

            if (unhandledException != null && !isHandledByDocument)
            {
                detailsMarkdown = InjectedManager.Markdown(unhandledException);
                var correlationTokenRequest = this.HttpContext.Request.Headers["X-CorrelationToken"].FirstOrDefault();
                Guid.TryParse(correlationTokenRequest, out var correlationToken);
                applicationSettings.UnhandledExceptionLogger.TraceError(correlationToken, detailsMarkdown);
            }
            RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

            //SqlException sqlException = null;
            var remoteServerErrorType = SqlServerManager.QuickAnalyze(unhandledException);

            if (remoteServerErrorType == RemoteServerErrorType.DOWN)
            {
                Message = "Adminka is currently down for maintenance. Back soon.";
                Title   = "Maintenance";
            }
            else if (remoteServerErrorType == RemoteServerErrorType.OVERLOADED)
            {
                Message = "Adminka is a bit overloaded right now... We are sorry asking you try again later";
                Title   = "Maintenance";
            }


            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (environment == "Development" || applicationSettings.ForceDetailsOnCustomErrorPage)
            {
                ShowAdvancedInformation = true;
            }
            else
            {
                var isAdminPrivilege = User.Claims.Any(c => c.Type == "PRIVILEGE" && c.Value == "ADMIN");
                if (isAdminPrivilege)
                {
                    ShowAdvancedInformation = true;
                }
            }
            if (ShowAdvancedInformation)
            {
                if (isHandledByDocument)
                {
                    var text = aspRoutineFeature.TraceDocument.Build();
                    ExceptionHtml = InjectedManager.ToHtml(text);
                }
                else if (unhandledException != null && detailsMarkdown != null)
                {
                    ExceptionHtml = InjectedManager.ToHtmlException(detailsMarkdown);
                }

                if (aspRoutineFeature != null)
                {
                    CorrelationToken = aspRoutineFeature.CorrelationToken.ToString();
                }
            }
        }
コード例 #3
0
        public static HtmlString MarkdownException(this IHtmlHelper helper, Exception exception)
        {
            var html = InjectedManager.ToHtml(exception);

            return(new HtmlString(html));
        }