How do you redirect to the error page?
Our solution has been to add this to the web.config httpErrors section:
<error statusCode="404" path="/404" responseMode="ExecuteURL" />
And registered a route for /404:
routes.MapRoute("404","404",new { controller = "Error", action = "NotFound" });
Inside the ErrorController we would still have the original info as we are still processing the same request from the client:
public ActionResult NotFound() { var pathAndQuery = Request.Url.PathAndQuery.ToLowerInvariant(); ... }
There might very well be nicer solutions out there though. :)
Hi Rajaa
You could take a look or even use the popular open source 404 handler for Episerver:
https://github.com/Geta/404handler
David
Hi,
Thank you for the help!
https://github.com/Geta/404handler was very good.
I redirect this way :
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="410" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Common/404/" responseMode="ExecuteURL" />
<error statusCode="410" prefixLanguageFilePath="" path="/Common/410/" responseMode="ExecuteURL" />
</httpErrors>
I have tried the
var pathAndQuery = Request.Url.PathAndQuery.ToLowerInvariant();
but then it gave me a string of a url, which seemed to be an impossible way to retreive a Pagedata going this way :( Am I wrong?
Am using the same ActionResult Method for all errors, 404, 410..and so on. the same viewModel and View. My goal wa to determine if the errorPage was triggered by a neverExisted Page, or by a page that has expired. coz i want to do differents things depending on the reason for the redirect. i Really hoped to get to the errorTriggererPage, using the current page (ErrorPage).
Thank you again:-)
// Rajaa
_urlResolver.Route(new UrlBuilder(url));
Normally gets you the PageData, but it probably won't work for an expired page, you can try to add a ContextMode as the second parameter to see if it helps.
Hello!1
Thnk you guys, really helpful!
I was over thinking it!
here is part of the solution:
if (language != null && errorLanguage != null && string.Compare(language.Name, errorLanguage.Name, StringComparison.InvariantCultureIgnoreCase) != 0) { ErrorPage currentSiteerrorPage = _contentLoader.Get<ErrorPage> (currentPage.ContentLink, language); if (currentSiteerrorPage != null) { if (pathAndQuery.ToLower().Contains("/archive")) // && !pathAndQuery.Contains("/oldpage") { Response.Status = "410 Gone"; _context.HttpContext.Response.StatusCode = 410; return View(currentSiteerrorPage.DefaultViewPath, _pageViewModelFactory.CreateViewModel(currentSiteerrorPage)); } _context.HttpContext.Response.StatusCode = 404; return View(currentSiteerrorPage.DefaultViewPath, _pageViewModelFactory.CreateViewModel(currentSiteerrorPage)); } }
Thank you1
// Rajaa
Hi,
I Am trying to get the page that redirected to my ErrorPage, so i can do things with it :
it should be somethink Like this
Am new to backend Dev. and new to Epi. Has anyone tried to solve this before? Any Ideas?
Thnx,
// Rajaa