public myStatusCodeHandling(IStatusCodeReExecuteFeature _statusCode, int?_StatusCode)
 {
     OriginalPathBase    = _statusCode.OriginalPathBase;
     OriginalPath        = _statusCode.OriginalPath;
     OriginalQueryString = _statusCode.OriginalQueryString;
     irStatusCode        = _StatusCode;
 }
Exemplo n.º 2
0
        //public IActionResult HTTPStatusCodeHandler(int statusCode)
        //{
        //    var statusCodeResult = HttpContext.Features.Get<IStatusCodeReExecuteFeature>();

        //    switch (statusCode)
        //    {
        //        case 404:

        //    }



        //}

        public IActionResult OnGet(int id)
        {
            IStatusCodeReExecuteFeature statusCodeResult = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

            switch (id)
            {
            case 404:
                _logger.LogWarning($"404 error occured. Path = {statusCodeResult.OriginalPath}");
                _logger.LogWarning($"404 error occured. Query string = {statusCodeResult.OriginalQueryString}");
                break;
            }


            var exceptionDetails = HttpContext.Features.Get <IExceptionHandlerPathFeature>();

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


            _logger.LogError($"Error RequestID: {RequestId.ToString()} ");


            //_logger.LogError($"The path {exceptionDetails.Path} threw an exception " +
            //    $"{exceptionDetails.Error}");

            return(Page());
        }
        public IActionResult Index(int statusCode)
        {
            IStatusCodeReExecuteFeature reExecute = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

            _logger.LogInformation($"Unexpected Status Code: {statusCode}, OriginalPath: {reExecute.OriginalPath}");
            return(View(statusCode));
        }
Exemplo n.º 4
0
        public IActionResult HTTP_404_Handler(IStatusCodeReExecuteFeature reExecuteFeature)
        {
            var logger = _loggerFactory.CreateLogger(LoggingConstants.PageNotFoundCategory);

            logger.LogInformation("The following path: {Path} was not found", reExecuteFeature.OriginalPath);

            return(View("NotFound"));
        }
Exemplo n.º 5
0
        public IActionResult Index(int?statusCode = null)
        {
            IStatusCodeReExecuteFeature reExecuteFeature = this.HttpContext.Features.Get <IStatusCodeReExecuteFeature>();
            ErrorViewModel errorModel = new ErrorViewModel {
                RequestId           = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier,
                StatusCode          = statusCode,
                OriginalPath        = reExecuteFeature?.OriginalPath,
                OriginalQueryString = reExecuteFeature?.OriginalQueryString
            };

            return(this.View("Error", errorModel));
        }
        public IActionResult Index(int errorCode)
        {
            IStatusCodeReExecuteFeature feature = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

            switch (errorCode)
            {
            case 404: {
                ViewBag.Message = "Page Could Not be Found";
                break;
            }
            }
            return(View());
        }
Exemplo n.º 7
0
        public IActionResult HttpStatusCodeHandler(int statusCode)
        {
            IStatusCodeReExecuteFeature statusCodeResult = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

            switch (statusCode)
            {
            case 404:
                ViewBag.ErrorMessage = "Sorry, the resource you requested cannot be found.";
                _logger.LogWarning($"404 error occured.\nPath = {statusCodeResult.OriginalPath}.\nQuery string = {statusCodeResult.OriginalQueryString}");
                break;
            }
            return(View("NotFound"));
        }
Exemplo n.º 8
0
        //page not found
        public virtual IActionResult PageNotFound()
        {
            if (_commonSettings.Log404Errors)
            {
                IStatusCodeReExecuteFeature statusCodeReExecuteFeature = HttpContext?.Features?.Get <IStatusCodeReExecuteFeature>();
                //TODO add locale resource
                _logger.Error($"Error 404. The requested page ({statusCodeReExecuteFeature?.OriginalPath}) was not found");
            }

            Response.StatusCode  = 404;
            Response.ContentType = "text/html";

            return(View());
        }
Exemplo n.º 9
0
        private async Task <IActionResult> TryNotFound(IStatusCodeReExecuteFeature feature)
        {
            IEnumerable <Post> searchResults = null;

            if (!string.IsNullOrWhiteSpace(feature?.OriginalPath))
            {
                var path = feature.OriginalPath;

                var knownRedirect = _settings.Redirects.FirstOrDefault(r => path.Equals(r.Find, StringComparison.OrdinalIgnoreCase));

                if (knownRedirect != null)
                {
                    return(Redirect(knownRedirect.Replace));
                }

                if (path.EndsWith('/'))
                {
                    path = path[0..^ 1];
Exemplo n.º 10
0
        public IActionResult Error(int statusCode)
        {
            if (statusCode == 404)
            {
                IStatusCodeReExecuteFeature statusDetail = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

                if (statusDetail.OriginalQueryString == null)
                {
                    Logger.LogError($"Message: Error 404! Page not found., Error-Path: {statusDetail.OriginalPath}");
                }
                else
                {
                    Logger.LogError($"Message: Error 404! Page not found., Error-Path: {statusDetail.OriginalPath}, " +
                                    $"Query String: {statusDetail.OriginalQueryString}");
                }
            }
            return(View("NotFound"));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Error404()
        {
            if (Request.Headers["Referer"].Count > 0)
            {
                ViewData["Reffer"] = Request.Headers["Referer"].ToString();

                IStatusCodeReExecuteFeature feature = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();
                Dictionary <string, Microsoft.Extensions.Primitives.StringValues> queryDictionary = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(feature?.OriginalQueryString);
                var requestedUrl = queryDictionary["ReturnUrl"][0].Split('/').Last();
                if (requestedUrl.Contains('?'))
                {
                    requestedUrl = requestedUrl.Split('?').First();
                }
                TempData["Message"] = $"You do not have permission to view: {requestedUrl}";
                return(Redirect(ViewData["Reffer"] as string));
            }
            return(await LoadWelcomeView());
        }
Exemplo n.º 12
0
    private ErrorInformation GetModel()
    {
        IStatusCodeReExecuteFeature statusCodeFeature = this.HttpContext.Features.Get <IStatusCodeReExecuteFeature>();
        StatusCodeReExecuteFeature? specific          = statusCodeFeature as StatusCodeReExecuteFeature;

        if (statusCodeFeature == null)
        {
            return(new ErrorInformation {
                OriginalPath = null,
                QueryString = null
            });
        }

        return(new ErrorInformation {
            OriginalPath = statusCodeFeature.OriginalPath,
            QueryString = specific?.OriginalQueryString
        });
    }
Exemplo n.º 13
0
        private IActionResult HandleStatus(int code, IStatusCodeReExecuteFeature feature)
        {
            OriginalUrl =
                feature.OriginalPathBase
                + feature.OriginalPath
                + feature.OriginalQueryString;
            Code      = code;
            RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

            switch (Code)
            {
            case (int)HttpStatusCode.NotFound:
                StatusCodeStyle = Resources.NotFoundMessageStyle;
                MessageTitle    = Localizer[Resources.NotFoundMessageTitle];
                Message         = Localizer[Resources.NotFoundMessage];
                break;

            case (int)HttpStatusCode.Forbidden:
                StatusCodeStyle = Resources.AccessDeniedMessageStyle;
                MessageTitle    = Localizer[Resources.AccessDeniedMessageTitle];
                Message         = Localizer[Resources.AccessDeniedMessage];
                break;

            case (int)HttpStatusCode.Unauthorized:
                StatusCodeStyle = Resources.UnauthorizedMessageStyle;
                MessageTitle    = Localizer[Resources.UnauthorizedMessageTitle];
                Message         = Localizer[Resources.UnauthorizedMessage];
                break;

            case (int)HttpStatusCode.BadRequest:
                StatusCodeStyle = Resources.BadRequestMessageStyle;
                MessageTitle    = Localizer[Resources.BadRequestMessageTitle];
                Message         = Localizer[Resources.BadRequestMessage];
                break;

            default:
                StatusCodeStyle = Resources.CommonMessageStyle;
                MessageTitle    = Localizer[Resources.CommonMessageTitle];
                Message         = Localizer[Resources.CommonMessage];
                break;
            }

            return(Page());
        }
Exemplo n.º 14
0
        public IActionResult HandleErrorCode(int statusCode)
        {
            IStatusCodeReExecuteFeature statusCodeData = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

            switch (statusCode)
            {
            case 404:
                ViewBag.ErrorMessage     = "Sorry the page you requested could not be found";
                ViewBag.RouteOfException = statusCodeData.OriginalPath;
                break;

            case 500:
                ViewBag.ErrorMessage     = "Sorry something went wrong on the server";
                ViewBag.RouteOfException = statusCodeData.OriginalPath;
                break;
            }
            ViewBag.StatusCode = statusCode;
            return(View());
        }
Exemplo n.º 15
0
        public IActionResult HTTP_406_Handler(IStatusCodeReExecuteFeature reExecuteFeature)
        {
            var    headersFeature     = HttpContext.Features.Get <IHttpRequestFeature>();
            string acceptHeaderValues = headersFeature.Headers["Accept"].ToString();

            var result = Json(new
            {
                Message = $"The requested path {reExecuteFeature.OriginalPath} does not support the format/s in the Accept header: {acceptHeaderValues}"
            });

            result.StatusCode = 406;

            var logger = _loggerFactory.CreateLogger(LoggingConstants.ContentNotAcceptableCategory);

            logger.LogInformation("The following {Path} does not permit the Accept header's following: {AcceptHeaderValues}",
                                  reExecuteFeature.OriginalPath, acceptHeaderValues);

            return(result);
        }
Exemplo n.º 16
0
        public IActionResult HttpStatusCodeHandler(int statusCode)
        {
            IStatusCodeReExecuteFeature statusCodeResult =
                this.HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

            switch (statusCode)
            {
            case 404:     // NotFound
                this.logger.LogWarning(
                    "404 Error Occurred." +
                    $" Path = {statusCodeResult.OriginalPath}" +
                    $" and QueryString = {statusCodeResult.OriginalQueryString}");
                return(this.View("NotFound"));
            }

            this.ViewBag.ErrorMessage = $"Error {statusCode}";

            return(this.View("Unknown"));
        }