There is alot of this going on in the forum. But i cant find any answers that solves my situation.
using Umbraco 7.5.8
I want to return the error page i am setting in umbracoSettings.config in my RenderMvcController. And i want to do so whitout changing the url.
First approach:
Returns errorPage.redirectID is null. I guess thats because i need to make a INotFoundHandler?
Second approach:
Just return the current content from the RenderModel passed to it.
public override ActionResult Index(RenderModel model)
{
// I only wanna return the 404 page when something is not right..
if (someConditionsAreNotMeet)
{
// I dunno if i need this.
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 404;
Response.Status = "404 Not Found";
// First approach
var errorPage = new umbraco.handle404();
errorPage.Execute(Request.Url.PathAndQuery);
var typedErrorPage = Umbraco.TypedContent(errorPage.redirectID);
model = new RenderModel(typedErrorPage);
// Second approach (1136 is the id of my 404 page).
var typedErrorPage = Umbraco.TypedContent(1136);
model = new RenderModel(typedErrorPage);
}
return base.Index(model);
}
public override ActionResult Index(RenderModel model)
{
if (someConditionsAreNotMeet)
{
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.StatusCode = 400;
System.Web.HttpContext.Current.Response.Status = "404 Page Not Found";
IPublishedContent c = Umbraco.TypedContent(1136);
RenderModel rm = new RenderModel(c);
return View(rm.Content.GetTemplateAlias(), rm);
}
return base.Index(model);
}
if you want to grab your umbracoSettings.config errorList you can do this:
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
IEnumerable<IContentErrorPage> umbracoSettingsErrorPages = UmbracoConfig.For.UmbracoSettings().Content.Error404Collection;
foreach (IContentErrorPage umbracoSettingsErrorPage in umbracoSettingsErrorPages.Where(x => x.HasContentId))
{
var errorPageId = umbracoSettingsErrorPage.ContentId;
var cultureInfoName = umbracoSettingsErrorPage.Culture;
}
Return 404 after hijacking umbraco route
Hello Everyone.
There is alot of this going on in the forum. But i cant find any answers that solves my situation.
using Umbraco 7.5.8
I want to return the error page i am setting in umbracoSettings.config in my RenderMvcController. And i want to do so whitout changing the url.
First approach:
Returns errorPage.redirectID is null. I guess thats because i need to make a INotFoundHandler?
Second approach:
Just return the current content from the RenderModel passed to it.
Any pointers would be appreciated.
I solved it by doing this.
if you want to grab your umbracoSettings.config errorList you can do this:
The logic for it, is for to you ;)
is working on a reply...