我一直在偷看Sitecore.Kernel,但似乎无法找到Sitecore运行Initialize管道的地方。它是在每个页面请求上运行还是仅在应用程序启动时运行一次?你能指出我为这个管道调用Run方法的确切位置吗?
更新
有理由我最后问这个问题是因为我在Sitecore的代码中追溯mvc.requestBegin
管道的执行。这是我发现的:
Initialize
管道运行InitializeRoutes
处理器... Sitecore.Mvc.Pipelines.Loader.InitializeRoutes.Process(PipelineArgs args)
打电话...... Sitecore.Mvc.Pipelines.Loader.InitializeRoutes.RegisterRoutes(RouteCollection routes, PipelineArgs args)
来电... Sitecore.Mvc.Pipelines.Loader.InitializeRoutes.SetRouteHandlers(RouteCollection routes, PipelineArgs args)
创建新的RouteHandlerWrapper
个对象这里的事情有点模糊......
Sitecore.Mvc.Routing.RouteHandlerWrapper.GetHttpHandler(RequestContext requestContext)
返回(IHttpHandler) new RouteHttpHandler
然后,最后......
Sitecore.Mvc.Routing.RouteHttpHandler.ProcessRequest(HttpContext context)
来电... Sitecore.Mvc.Routing.RouteHttpHandler.BeginRequest()
运行mvc.requestBegin
管道答案 0 :(得分:5)
我决定尝试在Sitecore 7.2的干净安装中添加一些调试功能。 我创建了以下简单类:
using Sitecore.Diagnostics;
using Sitecore.Pipelines;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
namespace SCMVC72.Pipelines
{
public class DebugStackTrace
{
public void Process(PipelineArgs args)
{
StackTrace st = new StackTrace();
Log.Info(string.Empty, (object)this);
Log.Info("*********************************************************************", (object)this);
Log.Info("Debug StackTrace", (object)this);
Log.Info(st.ToString(), (object)this);
Log.Info("*********************************************************************", (object)this);
}
}
}
我在App_Config\Include
文件夹中添加了以下配置文件:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<initialize>
<processor type="SCMVC72.Pipelines.DebugStackTrace, SCMVC72"
patch:before="processor[@type='Sitecore.Pipelines.Loader.ShowVersion, Sitecore.Kernel']" />
</initialize>
</pipelines>
</sitecore>
</configuration>
在应用程序重启时,这是我在日志中得到的输出:
5764 14:38:08 INFO HttpModule is being initialized
5764 14:38:08 INFO
5764 14:38:08 INFO *********************************************************************
5764 14:38:08 INFO Debug StackTrace
5764 14:38:08 INFO at SCMVC72.Pipelines.DebugStackTrace.Process(PipelineArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Nexus.Web.HttpModule.Application_Start()
at Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
5764 14:38:08 INFO *********************************************************************
这是着名的输出:
5764 14:38:08 INFO
5764 14:38:08 INFO **********************************************************************
5764 14:38:08 INFO **********************************************************************
5764 14:38:08 INFO Sitecore started
5764 14:38:08 INFO Sitecore.NET 7.2 (rev. 140228)
这证实了约翰·韦斯特在撰写“这种情况发生在其中一个混淆的集会中”时所说的约翰·韦斯特所说的话--Sitecore.Nexus,更确切地说。
答案 1 :(得分:4)
SetActiveSite
课程中有Sitecore.Context
个方法。这会运行Intialize
管道,并且有几个地方可以从中调用该方法。
JobRunner.InitalizeContext
MediaCreator.SetContext
MediaRequestHandler.RedirectIfUserShouldBeLoggedIn
WebDavMediaRequestHandler.ProcessRequest
因此它似乎与上下文的初始化相关联,因此不仅仅是在应用程序的开头。
有关信息,我通过搜索"Initalize"
(包含引号)找到了这个信息,发现了这一点:
CorePipeline.Run("initialize", new PipelineArgs());