コード例 #1
0
        public ActionResult Http404(string url, HandleErrorInfo error)
        {
            var exception = error.Exception;

            Response.StatusCode = (int)HttpStatusCode.NotFound;

            // If the url is relative ('NotFound' route), replace with Requested path
            var uri          = this.Request.Url;
            var requestedUrl = uri != null && uri.OriginalString != url &&
                               (url == null || uri.OriginalString.Contains(url))
                                   ? uri.OriginalString
                                   : url;

            // Don't get the user stuck in a 'retry loop' by allowing the Referrer to be the Request.
            var referrerUrl = this.Request.UrlReferrer != null && this.Request.UrlReferrer.OriginalString != requestedUrl
                                    ? this.Request.UrlReferrer.OriginalString
                                    : null;

            var model = new NotFoundViewModel {
                RequestedUrl = requestedUrl, ReferrerUrl = referrerUrl, Message = exception.Message
            };

            // TODO: log
            return(this.View("NotFound", model));
        }
コード例 #2
0
        public ActionResult Index()
        {
            var item = this._urlKeeperRepository.GetByOldPath(Request.RawUrl);

            if (item != null)
            {
                try
                {
                    var redirectUrl = this._urlResolver.GetUrl(PermanentLinkUtility.FindContentReference(item.ContentGuid));

                    if (redirectUrl != null)
                    {
                        Response.RedirectPermanent(redirectUrl, true);
                    }
                }
                catch
                {
                }
            }

            var pageNotFoundTitle = CommonHelpers.TranslateFallback("/views/pagenotfound/title", "Sorry");
            var pageNotFoundText  = CommonHelpers.TranslateFallback("/views/pagenotfound/text", "404\nThat page\ndoesn't seem\nto exist");
            var model             = new NotFoundViewModel
            {
                Title = pageNotFoundTitle,
                Text  = pageNotFoundText
            };

            Response.TrySkipIisCustomErrors = true;
            Response.StatusCode             = 404;

            return(View(model));
        }
コード例 #3
0
        public IActionResult NotFound(string key)
        {
            var vm = new NotFoundViewModel()
            {
                Key = key
            };

            return(View(vm));
        }
コード例 #4
0
        private NotFoundViewModel GetModel(string url)
        {
            var model = new NotFoundViewModel();

            model.RequestedUrl = Request.Url != null && Request.Url.OriginalString.Contains(url) & Request.Url.OriginalString != url ? Request.Url.OriginalString : url;
            model.ReferrerUrl  = Request.UrlReferrer != null && Request.UrlReferrer.OriginalString != model.RequestedUrl ? Request.UrlReferrer.OriginalString : null;

            return(model);
        }
コード例 #5
0
        public ActionResult NotFound(string url)
        {
            NotFoundViewModel model = new NotFoundViewModel
            {
                Url = url
            };

            return(View(model));
        }
コード例 #6
0
        public ActionResult Http404(string url)
        {
            Response.StatusCode = (int)HttpStatusCode.NotFound;
            var model = new NotFoundViewModel();

            // Если путь относительный ('NotFound' route), тогда его нужно заменить на запрошенный путь
            model.RequestedUrl = Request.Url.OriginalString.Contains(url) & Request.Url.OriginalString != url ?
                                 Request.Url.OriginalString : url;
            // Предотвращаем зацикливание при равенстве Referrer и Request
            model.ReferrerUrl = Request.UrlReferrer != null &&
                                Request.UrlReferrer.OriginalString != model.RequestedUrl ?
                                Request.UrlReferrer.OriginalString : null;

            return(View("NotFound", model));
        }
コード例 #7
0
ファイル: ErrorController.cs プロジェクト: Rocket18/WebStore
        public ActionResult Http404(string url)
        {
            Response.StatusCode = (int)HttpStatusCode.NotFound;
            var model = new NotFoundViewModel();
            // Если путь относительный ('NotFound' route), тогда его нужно заменить на запрошенный путь
            model.RequestedUrl = Request.Url.OriginalString.Contains(url) & Request.Url.OriginalString != url ?
                Request.Url.OriginalString : url;
            // Предотвращаем зацикливание при равенстве Referrer и Request
            model.ReferrerUrl = Request.UrlReferrer != null &&
                Request.UrlReferrer.OriginalString != model.RequestedUrl ?
                Request.UrlReferrer.OriginalString : null;

            // TODO: добавить реализацию ILogger

            return View("NotFound", model);
        }
コード例 #8
0
ファイル: ErrorController.cs プロジェクト: giagiigi/WE
        public ActionResult NotFound()
        {
            Response.StatusCode = 404;

            var customer = ControllerContext.HttpContext.GetCustomer();
            var topic    = new Topic("PageNotFound", customer.LocaleSetting, customer.SkinID, new Parser(), AppLogic.StoreID());

            var model = new NotFoundViewModel(
                title: topic.SectionTitle,
                content: topic.Contents,
                suggestions: AppLogic.AppConfigBool("Show404SuggestionLinks")
                                        ? GenerateSuggestions(customer)
                                        : null);

            return(View(model));
        }
コード例 #9
0
        public async Task <IActionResult> Details(string id)
        {
            var order = await this._orderService.GetOrderByIdWithInclude(id);

            if (order == null)
            {
                var errorViewModel = new NotFoundViewModel()
                {
                    StatusCode = 404,
                    Message    = $"Not found this id: {id}"
                };

                return(View("NotFound", errorViewModel));
            }

            return(View(this._mapper.Map <OrderDetailViewModel>(order)));
        }
コード例 #10
0
        public ActionResult Http404(string url)
        {
            Response.StatusCode = (int)HttpStatusCode.NotFound;
            var model = new NotFoundViewModel();
            // If the url is relative ('NotFound' route) then replace with Requested path
            model.RequestedUrl = Request.Url.OriginalString.Contains(url) & Request.Url.OriginalString != url ?
                Request.Url.OriginalString : url;
            // Dont get the user stuck in a 'retry loop' by
            // allowing the Referrer to be the same as the Request
            model.ReferrerUrl = Request.UrlReferrer != null &&
                Request.UrlReferrer.OriginalString != model.RequestedUrl ?
                Request.UrlReferrer.OriginalString : null;

            // TODO: insert ILogger here

            return View("NotFound", model);
        }
コード例 #11
0
        public virtual ViewResult Http404(string url)
        {
            Response.StatusCode = (int)System.Net.HttpStatusCode.NotFound;
            var model = new NotFoundViewModel();

            // If the url is relative ('NotFound' route) then replace with Requested path
            model.RequestedUrl = !string.IsNullOrEmpty(url) ?
                                 Request.Url.OriginalString.Contains(url) & Request.Url.OriginalString != url ?
                                 Request.Url.OriginalString : url : "";
            // Dont get the user stuck in a 'retry loop' by
            // allowing the Referrer to be the same as the Request
            model.ReferrerUrl = Request.UrlReferrer != null &&
                                Request.UrlReferrer.OriginalString != model.RequestedUrl ?
                                Request.UrlReferrer.OriginalString : null;

            // Log error
            //Elmah.ErrorSignal.FromCurrentContext().Raise(new HttpException(404,
            //    string.Format(ExceptionStrings.MVC404, model.RequestedUrl)));
            return(View(model));
        }
コード例 #12
0
        public async Task <IActionResult> ConfirmDelete(string id)
        {
            var order = await this._orderService.GetByIdAsync(id);

            if (order == null)
            {
                var errorViewModel = new NotFoundViewModel()
                {
                    StatusCode = 404,
                    Message    = $"Not found this id: {id}"
                };

                return(View("NotFound", errorViewModel));
            }

            try
            {
                var deleted = await this._orderService.DeleteAsync(order.Id);

                if (!deleted)
                {
                    this._logger.LogError($"Cannot delete this order, id: {id}");

                    return(View("Error", new ErrorViewModel()
                    {
                        ErrorTitle = "Delete Order", ErrorMessage = $"Cannot delete this order, id: {id}"
                    }));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException ex)
            {
                this._logger.LogError(ex.Message);

                return(View("Error", new ErrorViewModel()
                {
                    ErrorTitle = "Delete Order", ErrorMessage = ex.Message
                }));
            }
        }
コード例 #13
0
        public IActionResult HttpStatusCodeHandler(int statusCode)
        {
            var statusCodeResult = HttpContext.Features.Get <IStatusCodeReExecuteFeature>();

            switch (statusCode)
            {
            case 404:
            {
                var errorViewModel = new NotFoundViewModel()
                {
                    StatusCode = 404,
                    Message    = "Sorry, your request could not be found."
                };

                this._logger.LogWarning($"404 status code. Path = {statusCodeResult.OriginalPath}" + $" and QueryString = {statusCodeResult.OriginalQueryString}");
            }
            break;
            }

            return(View("NotFound"));
        }
コード例 #14
0
        public ActionResult Http404(string url, HandleErrorInfo error)
        {
            var exception = error.Exception;
            Response.StatusCode = (int)HttpStatusCode.NotFound;

            // If the url is relative ('NotFound' route), replace with Requested path
            var uri = this.Request.Url;
            var requestedUrl = uri != null && uri.OriginalString != url
                               && (url == null || uri.OriginalString.Contains(url))
                                   ? uri.OriginalString
                                   : url;

            // Don't get the user stuck in a 'retry loop' by allowing the Referrer to be the Request.
            var referrerUrl = this.Request.UrlReferrer != null && this.Request.UrlReferrer.OriginalString != requestedUrl
                                    ? this.Request.UrlReferrer.OriginalString
                                    : null;

            var model = new NotFoundViewModel { RequestedUrl = requestedUrl, ReferrerUrl = referrerUrl, Message = exception.Message };

            // TODO: log
            return this.View("NotFound", model);
        }
コード例 #15
0
        public async Task <IActionResult> ConfirmEmail(string userId, string token)
        {
            if (userId == null || token == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var user = await this._userManager.FindByIdAsync(userId);

            if (user == null)
            {
                var notFoundViewModel = new NotFoundViewModel()
                {
                    StatusCode = 404,
                    Message    = $"The user id: {userId} is invalid."
                };

                return(View("NotFound", notFoundViewModel));
            }

            var result = await this._userManager.ConfirmEmailAsync(user, token);

            if (result.Succeeded)
            {
                this._logger.LogInformation("User confirmed email.");

                return(View());
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    this._logger.LogError(string.Empty, error.Description);
                }

                return(View("Error"));
            }
        }
コード例 #16
0
        protected void Application_Error(object sender, EventArgs e)
        {
            var httpContext       = ((MvcApplication)sender).Context;
            var currentController = " ";
            var currentAction     = " ";
            var currentRouteData  = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));

            if (currentRouteData != null)
            {
                if (currentRouteData.Values["controller"] != null && !String.IsNullOrEmpty(currentRouteData.Values["controller"].ToString()))
                {
                    currentController = currentRouteData.Values["controller"].ToString();
                }

                if (currentRouteData.Values["action"] != null && !String.IsNullOrEmpty(currentRouteData.Values["action"].ToString()))
                {
                    currentAction = currentRouteData.Values["action"].ToString();
                }
            }

            var ex         = Server.GetLastError();
            var controller = new ErrorController();
            var routeData  = new RouteData();
            var action     = "Error";

            if (ex is HttpException)
            {
                var httpEx = ex as HttpException;

                switch (httpEx.GetHttpCode())
                {
                case 401:
                    action = "AccessDenied";
                    break;

                case 404:
                    action = "NotFound";
                    break;

                case 403:
                    action = "Forbidden";
                    break;

                default:
                    action = "Error";
                    break;
                }
            }

            httpContext.ClearError();
            httpContext.Response.Clear();
            httpContext.Response.StatusCode             = ex is HttpException ? ((HttpException)ex).GetHttpCode() : 500;
            httpContext.Response.TrySkipIisCustomErrors = true;

            routeData.Values["area"]       = "";
            routeData.Values["controller"] = "Error";
            routeData.Values["action"]     = action;

            var errorpath = currentController + "/" + currentAction;
            var model     = new NotFoundViewModel(ex, currentController, currentAction);

            model.RequestedUrl = Request.Url.OriginalString.Contains(errorpath) & Request.Url.OriginalString != errorpath ?
                                 Request.Url.OriginalString : errorpath;
            // Dont get the user stuck in a 'retry loop' by
            // allowing the Referrer to be the same as the Request
            model.ReferrerUrl = Request.UrlReferrer != null &&
                                Request.UrlReferrer.OriginalString != model.RequestedUrl ?
                                Request.UrlReferrer.OriginalString : null;

            controller.ViewData.Model = model;
            try
            {
                var hcw = new HttpContextWrapper(httpContext);
                var rc  = new RequestContext(hcw, routeData);
                ((IController)controller).Execute(rc);
            }
            catch
            {
                Response.Redirect("/Error/Error");
            }
        }
コード例 #17
0
 protected ActionResult NotFoundView(string WhatItIsThatIsntFound)
 {
     var Model = new NotFoundViewModel(){ WhatItIsThatIsntFound = WhatItIsThatIsntFound };
     return View("NotFound", Model);
 }