Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确定页面是静态.aspx页面还是不存在于sitecore管道中_Sitecore_Pipeline - Fatal编程技术网

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

确定页面是静态.aspx页面还是不存在于sitecore管道中,sitecore,pipeline,Sitecore,Pipeline,我在处理器上的Sitecore管道中工作。我需要确定发送的请求是否针对没有上下文项的静态.aspx页面,或者请求的页面是否不存在 这将在触发itemsolver进程后立即发生,因此对于管道中运行的.aspx和不存在的页面请求,数据库都设置为master 我无法检查Context.Item==null,因为静态页面没有与之关联的项,我希望保持这种方式,因为所述页面上的内容不会更改 让我知道如果你有任何想法来区分这些 您可能可以使用Sitecore.Context.Page.FilePath。在Si

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

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

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


让我知道如果你有任何想法来区分这些

您可能可以使用
Sitecore.Context.Page.FilePath
。在Sitecore项目(即“/layouts/standard Layout.aspx”)上,它将设置为您的
布局,而在静态页面上,它将是您页面的路径


如果您的静态页面都位于与Sitecore布局不同的位置,那么只需匹配
文件路径的一部分就可以了,您可以使用
Sitecore.Context.Page.FilePath
。在Sitecore项目(即“/layouts/standard Layout.aspx”)上,它将设置为您的
布局,而在静态页面上,它将是您页面的路径


如果您的静态页面都位于与Sitecore布局不同的位置,那么只需匹配
文件路径的一部分就可以了,我想您已经部分回答了自己的问题

如果将组件放在ItemResolver之后的httpBeginRequest管道中,则应该能够检查
Context.Item==null
。如果它是
null
,则您知道URL不会解析为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>

我想你部分回答了自己的问题

如果将组件放在ItemResolver之后的httpBeginRequest管道中,则应该能够检查
Context.Item==null
。如果它是
null
,则您知道URL不会解析为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>


哇,太好了!如果正在使用sitecore项目,则仅在ItemResolver之后将quick note Context.Page.FilePath设置为“”。奇怪的是,当发送到/doesntexist.aspx的请求被设置为“”时,static.aspx页面有一个路径,就像项目的文件路径一样。要筛选出现有的.aspx页面和包含项目的页面,只需检查(Context.Item | | | Context.Page.FilePath!=“”)。我觉得这可能会让我大发雷霆,所以我将对它进行一些测试,然后更新此评论。如果您看到任何危险,请告诉我,谢谢!请记住,如果项目未指定任何布局详细信息,Context.Page.FilePath也将为空。在这种情况下,您可能仍然需要404,但需要注意的是,这是我没有想到的。谢谢你的提醒。我将尝试使用案例404,除非它是sitecore中存在的图像(没有演示细节,但我希望sc处理并显示它)。哇,太好了!如果正在使用sitecore项目,则仅在ItemResolver之后将quick note Context.Page.FilePath设置为“”。奇怪的是,当发送到/doesntexist.aspx的请求被设置为“”时,static.aspx页面有一个路径,就像项目的文件路径一样。要筛选出现有的.aspx页面和包含项目的页面,只需检查(Context.Item | | | Context.Page.FilePath!=“”)。我觉得这可能会让我大发雷霆,所以我将对它进行一些测试,然后更新此评论。如果您看到任何危险,请告诉我,谢谢!请记住,如果项目未指定任何布局详细信息,Context.Page.FilePath也将为空。在这种情况下,您可能仍然需要404,但需要注意的是,这是我没有想到的。谢谢你的提醒。我将尝试使用案例404,除非它是sitecore中存在的图像(没有演示详细信息,但我希望sc处理和显示它)。在这种情况下,检查sitecore.Context.Page.FilePath==“”和args.Context.Server.MapPath(args.Context.Request.RawUrl)之间是否存在差异==空?是的,有很大的区别。在这段代码中,您正在检查“DidItemResolver解析一个项目”。如果没有,那么您将看到IIS是否解析了ASPX页面。在检查Server.MapPath时,Sitecore.Context.Page将为null并引发NullRef异常。在这种情况下,检查Sitecore.Context.Page.FilePath==“”和args.Context.Server.MapPath(args.Context.Request.RawUrl)==null之间是否存在差异?是的,差异很大。在这段代码中,您正在检查“DidItemResolver解析一个项目”。如果没有,那么您将看到IIS是否解析了ASPX页面。在检查Server.MapPath时,Sitecore.Context.Page将为null并引发NullRef异常。