Sitecore - 多站点错误页面处理
我有一个多站点 Sitecore 项目。我知道如何通过 webconfig 的 ErrorPage、ItemNotFoundUrl、LayoutNotFoundUrl、LinkItemNotFoundUrl 处理一个站点的错误页面。
但是,我想为每个站点显示不同的错误页面。我怎样才能做到这一点?
I have a multiple-site Sitecore project. I know how to deal with error pages via the webconfig's ErrorPage, ItemNotFoundUrl, LayoutNotFoundUrl, LinkItemNotFoundUrl for one site.
However, I'm wanting to display a different error pages for each site. How can I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在任何情况下,您都可以通过扩展
Sitecore.Sites 将每个站点的错误页面的 URL 存储为 web.config 中
类(请参阅有关扩展现有类的信息)。/configuration/sitecore/sites/site
元素的属性.SiteContextSDN 论坛帖子专门提供了有关 404
的更多信息/ItemNotFound
条件,包括Sitecore.SItes.SiteContext
扩展的示例。对于
ItemNotFoundUrl
,我认为这取决于您是否使用项目或文件作为 404 页面。如果您使用项目处理 404,则在项目解析器之后,将处理器添加到httpRequestBegin
管道,以将上下文项设置为该站点的 404 项(如果上下文项为 null)。如果您使用文件,那么我认为重写Sitecore.Pipelines.HttpRequest.ExecuteRequest.HandleItemNotFound()
和Sitecore.Resources.Media.MediaRequestHandler.DoProcessRequest()
并更新相应的web.config 文件中的引用。对于
ErrorPage
,我认为您必须覆盖Sitecore.Pipelines.RenderLayout.SecurityCheck.Process
并更新 web.config 中的相应引用。对于 LayoutNotFoundUrl ,我认为您必须重写 Sitecore.Pipelines.HttpRequest.ExecuteRequest.HandleLayoutNotFound ,并更新 web.config 中的相应引用。
对于 LinkItemNotFoundUrl,我可能会向 renderField 管道添加一个处理器,以将设置的默认值替换为适用于上下文站点的值。
如果这是一个常见的需求,我们应该将其变成Sitecore共享源项目,或者将其添加到现有项目中。
In any case, you can probably store the URLs of the error pages for each site as attributes of the
/configuration/sitecore/sites/site
elements in web.config by extending theSitecore.Sites.SiteContext
class (see for information about extending existing classes).The SDN forum post provides more information specifically about the 404
/ItemNotFound
condition, including an example of an extension ofSitecore.SItes.SiteContext
.For
ItemNotFoundUrl
, I think it depends on whether you use an item or a file as the 404 page. If you handle 404 with items, then after the item resolver, add a processor to thehttpRequestBegin
pipeline to set the context item to the 404 item for that site if the context item is null. If you use files, then I think overrideSitecore.Pipelines.HttpRequest.ExecuteRequest.HandleItemNotFound()
andSitecore.Resources.Media.MediaRequestHandler.DoProcessRequest()
and update the corresponding references in the web.config file.For
ErrorPage
, I think you would have to overrideSitecore.Pipelines.RenderLayout.SecurityCheck.Process
and update the corresponding reference in web.config.For
LayoutNotFoundUrl
, I think you would have to overrideSitecore.Pipelines.HttpRequest.ExecuteRequest.HandleLayoutNotFound
, and update the corresponding reference in web.config.For
LinkItemNotFoundUrl
, I would probably add a processor to the renderField pipeline to perform replacement of the default value of the setting with the value that applies for the context site.If this is a common requirement, we should turn it into a Sitecore Shared Source project, or add it to an existing project.
在 SDN 剪贴簿中有一个 条目,介绍如何对多- 现场安装。
There's an entry in the SDN scrapbook about how to do this for a multi-site install.
有一个共享源项目应该满足大部分要求。它称为 Sitecore 错误管理器。
希望有帮助。
There is a Shared Source project which should fit the requirements is most parts. It's called Sitecore Error Manager.
Hope that helps.