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

发布于 2024-11-28 05:41:44 字数 1898 浏览 2 评论 0原文

我正在尝试将自定义 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>

就像在其他项目中一样 虽然我不断收到 IIS 404 页面。

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

passThrough 给出了以下内容:

找不到页面 没有与 url 匹配的 umbraco 文档 'http://www.mysite.be/en/facebook'

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

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

有关详细信息,请访问有关自定义 404 的信息 umbraco 网站。

自定义给出了这个结果:

找不到页面 没有与 url 匹配的 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')

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

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

在我看来,好像他没有去 umbracoSettings 来获取我的 error404 映射。 4.7 中是否发生了一些变化,您需要通过 web.config 键激活自定义错误页面?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原来是傀儡 2024-12-05 05:41:44

对于那些感兴趣的人,或者可能遇到同样问题的人
没有任何 web.config 更改就解决了这个问题。

但通过使用自定义 404 处理程序,我们将其添加到 404handlers.config
像这样

  <notFound assembly="ProjectLibrary" type="Custom404"/>

,仍然在 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>

自定义处理程序看起来像这样:

    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
    }

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文