确定页面是静态.aspx页面还是在sitecore管道中不存在

时间:2013-07-23 23:49:06

标签: sitecore pipeline

我在处理器上的Sitecore管道中工作。我需要确定发送的请求是针对没有上下文项的静态.aspx页面,还是请求的页面不存在。

这将在ItemResolver进程触发后立即发生,因此对于正在运行管道的master和对不存在的页面的请求,数据库都设置为.aspx

我无法检查Context.Item == null是否因为静态页面没有与之关联的项目而且我希望保持这种方式,因为所述页面上的内容不会改变。

如果您有任何想法可以区分它们,请告诉我们!

2 个答案:

答案 0 :(得分:2)

您可以使用Sitecore.Context.Page.FilePath。它将在Sitecore项目上设置为Layout(即'/ layouts / standard layout.aspx'),而在静态页面上,它将成为您网页的路径。

如果您的静态网页与Sitecore布局位于不同的位置,则可能只是与FilePath的部分匹配一样简单。

答案 1 :(得分:2)

我认为你已经部分回答了自己的问题。

如果您在ItemResolver之后将组件放在httpBeginRequest管道中,您应该能够检查Context.Item == null。如果是null,则您知道该网址未解析为Sitecore项目。此时,您可以使用HttpContext.Current.Server.MapPath()查看它是否解析为路径。如果是,那么你就知道它是一个静态的.aspx文件。类似的东西:

public class CheckPath : HttpRequestProcessor
{
    public override void Process(HttpRequestArgs args)
    {
        if (Sitecore.Context.Item == null)
        {
            if (args.Context.Server.MapPath(args.Context.Request.RawUrl) == null)
            {
                // 404
            }
            else
            {
                // Static
            }
        }
        else 
        {
            // Sitecore item
        }
    }
}

将其修补到httpBeginRequest管道:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <httpRequestBegin>
                <processor patch:after="*[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" type="MyNamespace.CheckPath, MyAssemblyName" />
            </httpRequestBegin>
        </pipelines>
    </sitecore>
</configuration>