add custom 404 pages in umbraco 4.7
I'm trying to add custom 404 pages into umbraco even though I got them working in several projects, in this umbraco 4.7 it does not work.
so, what do I have, multi site each with a few languages.
my umbracoSettings contains this:
<errors>
<error404>
<errorPage culture="default">1842</errorPage>
<开发者_运维知识库;errorPage culture="en-GB">1842</errorPage>
<errorPage culture="nl-BE">1843</errorPage>
<errorPage culture="fr-BE">1844</errorPage>
</error404>
</errors>
just as it is in other projects though i keep getting the IIS 404 page.
so, i tried the solution in this topic both the passThrough and the custom solution don't seem to work
the passThrough gives this:
Page not found No umbraco document matches the url 'http://www.mysite.be/en/facebook'
umbraco tried this to match it using this xpath query'/domainprefixes-are-used-so-i-do-not-work')
This page can be replaced with a custom 404 page by adding the id of the umbraco document to show as 404 page in the /config/umbracoSettings.config file. Just add the id to the '/settings/content/errors/error404' element.
For more information, visit information about custom 404 on the umbraco website.
and custom gives this result:
Page not found No umbraco document matches the url 'http://solex.d01-win-dev.be/non-existing-page.aspx?404;http://solex.d01-win-dev.be:80/en/facebook'
umbraco tried this to match it using this xpath query'/domainprefixes-are-used-so-i-do-not-work')
This page can be replaced with a custom 404 page by adding the id of the umbraco document to show as 404 page in the /config/umbracoSettings.config file. Just add the id to the '/settings/content/errors/error404' element.
For more information, visit information about custom 404 on the umbraco website.
it looks to me as if he does not go towards the umbracoSettings to fetch my error404 mappings. did something change in 4.7 that you need to activate custom error pages trough a web.config key?
for those people interested, or who might ever have the same issues it was solved without any of those web.config changes.
but by using a custom 404 handler we added to the 404handlers.config
like this
<notFound assembly="ProjectLibrary" type="Custom404"/>
and still adding the error pages in the umbracoSettings.config
like this
<errors>
<error404>
<errorPage culture="default">1842</errorPage>
<errorPage culture="en-GB">1842</errorPage>
<errorPage culture="nl-BE">1843</errorPage>
<errorPage culture="fr-BE">1844</errorPage>
</error404>
</errors>
the custom handler looks like this:
public class Custom404 : INotFoundHandler
{
#region INotFoundHandler Members
private int _redirectID = -1;
public bool CacheUrl
{
get { return false; }
}
public bool Execute(string url)
{
//Variable for keeping track whether the handling of the request was successful
bool _success = false;
XmlNode error404Node = umbraco.UmbracoSettings.GetKeyAsNode("/settings/content/errors/error404");
// _redirectID =;
XmlNode cultureErrorNode;
try
{
HttpContext.Current.Trace.Write("test", HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/" + url);
string sDomein = findDomein(HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/" + url);
HttpContext.Current.Trace.Write("test", sDomein);
if (Domain.Exists(sDomein))
{
Domain d = Domain.GetDomain(sDomein);
// test if a 404 page exists with current culture
HttpContext.Current.Trace.Write("test", d.Language.CultureAlias);
cultureErrorNode = error404Node.SelectSingleNode(String.Format("errorPage [@culture = '{0}']", d.Language.CultureAlias));
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
{
_redirectID = int.Parse(cultureErrorNode.FirstChild.Value);
}
else
{
cultureErrorNode = error404Node.SelectSingleNode("errorPage [@culture = 'default']");
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
_redirectID = int.Parse(cultureErrorNode.FirstChild.Value);
}
}
else
{
cultureErrorNode = error404Node.SelectSingleNode("errorPage [@culture = 'default']");
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
_redirectID = int.Parse(cultureErrorNode.FirstChild.Value);
}
}
catch
{
cultureErrorNode = error404Node.SelectSingleNode("errorPage [@culture = 'default']");
if (cultureErrorNode != null && cultureErrorNode.FirstChild != null)
_redirectID = int.Parse(cultureErrorNode.FirstChild.Value);
}
_success = true;
return _success;
}
public string findDomein(string sUrl)
{
if (sUrl.Contains("/"))
{
if (Domain.Exists(sUrl))
{
return sUrl;
}
else
{
sUrl = sUrl.Substring(0, sUrl.LastIndexOf("/"));
return findDomein(sUrl);
}
}
else
{
return sUrl;
}
}
public int redirectID
{
get
{ return _redirectID; }
}
#endregion
}
hope any of you can use it whenever you find yourself in the same situation.
精彩评论