Skip to content

Instantly share code, notes, and snippets.

@pedroadaodev
Last active April 15, 2021 14:24
Show Gist options
  • Save pedroadaodev/30e59ef40c47b84bb2c5d3c2df52d0c0 to your computer and use it in GitHub Desktop.
Save pedroadaodev/30e59ef40c47b84bb2c5d3c2df52d0c0 to your computer and use it in GitHub Desktop.
UmbracoControllerRedirectTo404Page
public class ProductController : Umbraco.Web.Mvc.RenderMvcController
{
public ActionResult ProductPageTemplate(RenderModel model, string productId)
{
if(productId.IsValidProductInDatabase())
{
// Product is valid
return base.Index(model);
}
else
{
// redirect to 404 page
// send HTTP STATUS CODE 404
var errorPage = new umbraco.handle404();
errorPage.Execute(HttpContext.Request.Url.PathAndQuery);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.StatusCode = 404;
System.Web.HttpContext.Current.Response.Status = "404 Page Not Found";
System.Web.HttpContext.Current.Response.TrySkipIisCustomErrors = true;
var page404 = Umbraco.TypedContent(myNodeIdContent404PageInt);
return View("NotFoundPage", page404);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment