using System.Net; using System.Web.Mvc; namespace EnVisage.Controllers { public class ErrorController : Controller { 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 if (!string.IsNullOrEmpty(url)) 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("Http404", model); } public ActionResult Http500() { Response.StatusCode = (int)HttpStatusCode.InternalServerError; // TODO: insert ILogger here return View("Http500"); } public ActionResult Index() { return View("Error"); } public class NotFoundViewModel { public string RequestedUrl { get; set; } public string ReferrerUrl { get; set; } } } }