Last active
April 15, 2021 14:24
-
-
Save pedroadaodev/30e59ef40c47b84bb2c5d3c2df52d0c0 to your computer and use it in GitHub Desktop.
UmbracoControllerRedirectTo404Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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