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)); }
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)); }
public IActionResult NotFound(string key) { var vm = new NotFoundViewModel() { Key = key }; return(View(vm)); }
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); }
public ActionResult NotFound(string url) { NotFoundViewModel model = new NotFoundViewModel { Url = url }; return(View(model)); }
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)); }
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); }
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)); }
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))); }
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); }
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)); }
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 })); } }
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")); }
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); }
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")); } }
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"); } }
protected ActionResult NotFoundView(string WhatItIsThatIsntFound) { var Model = new NotFoundViewModel(){ WhatItIsThatIsntFound = WhatItIsThatIsntFound }; return View("NotFound", Model); }