Example #1
0
        /// <summary>
        /// Use this in your controllers to return a 404 result using the Cofoundry custom 404 page system. This
        /// has the added benefit of checking for Rewrite Rules and automatically redirecting.
        /// </summary>
        public async Task <ActionResult> GetViewAsync()
        {
            var path = HttpContext.Current.Request.Path;

            var result = await GetRewriteResultAsync(path);

            if (result != null)
            {
                return(result);
            }

            var vmParams = new NotFoundPageViewModelBuilderParameters(path);
            var vm       = await _pageViewModelBuilder.BuildNotFoundPageViewModelAsync(vmParams);

            HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.NotFound;

            return(new ViewResult()
            {
                ViewName = "NotFound",
                ViewData = new ViewDataDictionary(vm)
            });
        }
Example #2
0
        /// <summary>
        /// Use this in your controllers to return a 404 result using the Cofoundry custom 404 page system. This
        /// has the added benefit of checking for Rewrite Rules and automatically redirecting.
        /// </summary>
        public async Task <ActionResult> GetViewAsync(Controller controller)
        {
            var vmParameters = GetViewModelBuilerParameters(controller);

            var result = await GetRewriteResultAsync(vmParameters);

            if (result != null)
            {
                return(result);
            }

            var vm = await _pageViewModelBuilder.BuildNotFoundPageViewModelAsync(vmParameters);

            // in some situations the status code may not be set, so make sure it is.
            if (controller.Response.StatusCode != vm.StatusCode)
            {
                controller.Response.StatusCode = vm.StatusCode;
            }

            var viewName = FindView();

            return(controller.View(viewName, vm));
        }