public IActionResult Index(int?statusCode = null)
        {
            HttpErrorViewModel context = new HttpErrorViewModel();

            if (statusCode != null)
            {
                context.Code = (int)statusCode;
                if ((int)statusCode >= 400 && (int)statusCode < 500)
                {
                    context.Description = "Ошибка клиента.";
                    switch ((int)statusCode)
                    {
                    case 400: context.Description += " Неверный запрос."; break;

                    case 401: context.Description += " Не авторизован."; break;

                    case 403: context.Description += " Доступ запрещён."; break;

                    case 404: context.Description += " Запрашиваемый ресурс не найден."; break;

                    case 405: context.Description += " Неизвестный метод запроса."; break;

                    case 409: context.Description += " Конфликт запроса с текущим состоянием сервера."; break;

                    default: break;
                    }
                }
            }
            return(View(context));
        }
Exemple #2
0
        public IActionResult HttpError(HttpErrorViewModel errorViewModel)
        {
            if (errorViewModel.StatusCode == 404)
            {
                return(this.View(errorViewModel));
            }

            return(this.Error());
        }
Exemple #3
0
        public IActionResult HttpError(HttpErrorViewModel errorViewModel)
        {
            if (errorViewModel.StatusCode == 404)
            {
                return(this.View(errorViewModel));
            }

            return(this.View("Error", new ErrorViewModel {
                RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier
            }));
        }
Exemple #4
0
    public IActionResult HttpErrorPage(string code)
    {
        switch (code)
        {
        case "404":
            var model = new HttpErrorViewModel {
                Title = _localizer["Title"], Error = "404", Description = _localizer["Description"], Back = _localizer["Back"]
            };
            return(View(model));

        default:
            return(NoContent());
        }
    }
Exemple #5
0
        protected override void HandleUnknownAction(string actionName)
        {
            var controllerName = (string)RouteData.Values["controller"];
            var ex             = Server.GetLastError();
            var model          = new HttpErrorViewModel(ex ?? new HttpException(500, "Something went wrong."), controllerName, actionName);
            var result         = new ViewResult
            {
                ViewName = "~/Views/Error/Index.cshtml",
                ViewData = new ViewDataDictionary <HttpErrorViewModel>(model),
            };


            Response.StatusCode = model.StatusCode;
            result.ExecuteResult(ControllerContext);
        }
Exemple #6
0
        public ActionResult NotFound(string url)
        {
            var originalUri = url ?? Request.QueryString["aspxerrorpath"] ?? Request.Url.OriginalString;

            var controllerName = (string)RouteData.Values["controller"];
            var actionName     = (string)RouteData.Values["action"];
            var model          = new HttpErrorViewModel(new HttpException(404, "Failed to find page"), controllerName, actionName)
            {
                RequestedUrl = originalUri,
                ReferrerUrl  = Request.UrlReferrer == null ? "" : Request.UrlReferrer.OriginalString
            };

            Response.StatusCode = 404;
            return(View("Index", model));
        }
        public IActionResult HttpError(int statusCode, string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                message = "Не успяхме да намерим стрaницата която търсите";
            }

            var viewModel = new HttpErrorViewModel
            {
                StatusCode = statusCode,
                Message    = message,
            };

            return(this.View(viewModel));
        }
Exemple #8
0
        public virtual ActionResult Error404(string aspxerrorpath = null)
        {
            if (string.IsNullOrEmpty(aspxerrorpath) && Request.UrlReferrer != null)
            {
                aspxerrorpath = Request.UrlReferrer.PathAndQuery;
            }
            var vd = new HttpErrorViewModel
            {
                Url     = aspxerrorpath,
                ErrCode = 404
            };

            Response.StatusCode = (int)HttpStatusCode.NotFound;
            var result = View("Error404", vd);//HttpNotFound();

            return(result);
        }
Exemple #9
0
        public IActionResult HttpError(int statusCode)
        {
            var viewModel = new HttpErrorViewModel
            {
                StatusCode = statusCode,
            };

            if (statusCode == 404)
            {
                return(this.View(viewModel));
            }

            return(this.View(
                       "Error", new ErrorViewModel {
                RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier
            }));
        }
Exemple #10
0
        public IActionResult HttpError(int id)
        {
            HttpErrorViewModel model = new HttpErrorViewModel {
                StatusCode = id
            };

            switch (id)
            {
            case 400:
                model.ErrorTitle       = "Bad Request";
                model.ErrorDescription = "Your browser sent a request that this server could not understand.";
                break;

            case 401:
                model.ErrorTitle       = "Unauthorized";
                model.ErrorDescription = "This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.";
                break;

            case 403:
                model.ErrorTitle       = "Forbidden";
                model.ErrorDescription = "You don't have permission to access this resource.";
                break;

            case 404:
                model.ErrorTitle       = "Not Found";
                model.ErrorDescription = "The requested URL was not found on this server.";
                break;

            case 405:
                model.ErrorTitle       = "Method Not Allowed";
                model.ErrorDescription = "The target resource does not support the presented method.";
                break;

            case 500:
                model.ErrorTitle       = "Internal Server Error";
                model.ErrorDescription = "The server encountered an internal error or misconfiguration and was unable to complete your request.";
                break;

            default:
                model.ErrorTitle       = "HTTP error " + id;
                model.ErrorDescription = "HTTP error " + id;
                break;
            }
            return(View(model));
        }