Is it possible, and if so how do you return the standard Umbraco 404 error from a RenderMvcController? This beautiful bad boy:
In my scenario, I am using a UmbracoVirtualNodeRouteHandler to handle a custom route. A RenderMvcController is responsible for pulling the content from a remote API via ID. If the content doesn't exist, I'd like to return the same 404 page generated by normal Umbraco routing.
Here's how I'm currently doing it. This returns an IIS error page though.
var remoteContent = await _service.Get(id);
if (remoteContent == null) return new HttpNotFoundResult();
We already did something similar. I will add it here in case someone finds it useful:
public override IActionResult Index()
{
if (IsExpiredJob())
{
return HttpNotFoundPage();
}
return CurrentTemplate(CurrentPage);
}
private ViewResult HttpNotFoundPage()
{
var home = CurrentPage.Root<HomePage>();
Response.Clear();
Response.StatusCode = (int)HttpStatusCode.NotFound;
var error404 = home.DescendantOrSelf<Error404>();
var contentModel = new ContentModel(error404);
var viewData = new ViewDataDictionary(
new Microsoft.AspNetCore.Mvc.ModelBinding.EmptyModelMetadataProvider(),
new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary()
)
{
Model = contentModel
};
var viewResult = new ViewResult
{
ViewData = viewData,
ViewName = contentModel.Content.GetTemplateAlias(),
};
return viewResult;
}
Return Umbraco 404 from RenderMvcController
Hi guys,
Is it possible, and if so how do you return the standard Umbraco 404 error from a RenderMvcController? This beautiful bad boy:
In my scenario, I am using a UmbracoVirtualNodeRouteHandler to handle a custom route. A RenderMvcController is responsible for pulling the content from a remote API via ID. If the content doesn't exist, I'd like to return the same 404 page generated by normal Umbraco routing.
Here's how I'm currently doing it. This returns an IIS error page though.
Any help is greatly appreciated. TIA!
Hey Philip, did you manage to resolve this? I need the same thing.
I struggled for a bit returning umbraco's configured not found page from my own virtual page controllers.
I'm not sure if our situation is the same (I'm on v15) but this is what I ended up with in case you are out of ideas.
Where that guid is the one configured in my appsettings.json
Thanks npack,
We already did something similar. I will add it here in case someone finds it useful:
It's for version 13 though.
is working on a reply...