在umbraco 4.7中添加自定义404页面

San*_*der 1 error-handling umbraco

我正在尝试将自定义404页面添加到umbraco中,即使我让它们在多个项目中工作,在这个umbraco 4.7中它也不起作用.

所以,我有什么,多个站点,每个都有几种语言.

我的umbracoSettings包含这个:

    <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>
Run Code Online (Sandbox Code Playgroud)

就像在其他项目中一样,虽然我一直在获取IIS 404页面.

所以,我尝试了本主题中的解决方案, passThrough和自定义解决方案似乎都不起作用

passThrough给出了:

未找到页面没有umbraco文档与网址" http://www.mysite.be/en/facebook " 匹配

umbraco尝试使用此xpath查询匹配它'/ domainprefixes-are-used-so-i-do-not-work')

通过添加umbraco文档的ID以在/config/umbracoSettings.config文件中显示为404页面,可以将此页面替换为自定义404页面.只需将id添加到'/ settings/content/errors/error404'元素即可.

有关更多信息,请访问umbraco网站上有关自定义404的信息.

和自定义给出了这个结果:

未找到页面没有umbraco文档与网址' http://solex.d01-win-dev.be/non-existing-page.aspx?404 ;http ://solex.d01-win-dev.be:80/匹配en/facebook '

umbraco尝试使用此xpath查询匹配它'/ domainprefixes-are-used-so-i-do-not-work')

通过添加umbraco文档的ID以在/config/umbracoSettings.config文件中显示为404页面,可以将此页面替换为自定义404页面.只需将id添加到'/ settings/content/errors/error404'元素即可.

有关更多信息,请访问umbraco网站上有关自定义404的信息.

它看起来好像他没有走向umbracoSettings来获取我的error404映射.在4.7中你做了一些改变,你需要通过web.config键激活自定义错误页面?

San*_*der 5

对于那些感兴趣的人,或者可能遇到同样问题的人,如果没有任何web.config更改,它就会被解决.

但通过使用自定义404处理程序,我们添加了404handlers.config 这样的

  <notFound assembly="ProjectLibrary" type="Custom404"/>
Run Code Online (Sandbox Code Playgroud)

并且还添加在错误页面umbracoSettings.config 这样

  <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>
Run Code Online (Sandbox Code Playgroud)

自定义处理程序如下所示:

    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
    }
Run Code Online (Sandbox Code Playgroud)

希望你们中任何一个人在遇到同样的情况时都可以使用它.