The other day, I had an happy coding/analysis session at work when it transform into a nightmare … 😉
I wanted to achieve the following scenario:
I’ve products which are stored in a bucket outside the home tree and I’ve create a wildcard page under my home node which will link those products to that page.
I put a pipelines after the ItemResolver and if we are on a Wildcard template, i’m fetching the right product in my bucket folder and I store it in my request cache.
In the case were I don’t find it; I set the Sitecore.Context.Item to null and then well the ErrorPage mechanism will show me a 404.
Basic, Easy no ? 🙂
That was without considering that, as the project is in MVC, another pipeline will reset my Sitecore.Context.Item at a specific moment which totally put all my effort to a « Nothing is happening ».
So where does it reset the context.Item, well here :
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.SetLanguage, Sitecore.Mvc"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteValue, Sitecore.Mvc"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteUrl, Sitecore.Mvc"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromOldContext, Sitecore.Mvc"/>
<processor type="Sitecore.ContentTesting.Mvc.Pipelines.Response.GetPageItem.GetFromTestSet, Sitecore.ContentTesting.Mvc" patch:source="Sitecore.ContentTesting.Mvc.config"/>
And in this code specifically
Item item = PipelineService.Get().RunPipeline<GetPageItemArgs, Item>("mvc.getPageItem", new GetPageItemArgs(), (GetPageItemArgs args) => args.Result);
if (item != null)
if (Context.Language == null || Context.Language != item.Language)
Context.Language = item.Language;
if (Context.Item == null <strong>|| Context.Item.ID != item.ID)</strong>
Context.Item = item;
result = item;
So, the processor solved the context with the URL probably, and then he’s trying to look if the Context.Item.ID != item.ID which will be true (my wildcard Page against the fact that I want to leave the sitecore context to null because no products was found).
Well, one solution can be to set the Args.Result to the Sitecore Context Item at the beginning of the pipelines. Then it will abort those pipelines at the very beginning but I’m in a very big solution, and i don’t know if someone else is using it for a specific case.
So, I’ve put a pipelines at the end checking again that we have a Wildcard page, and if it’s the case, set the args.Result to the Sitecore.context.item (which can be my 404).
And I hope it will helps you if you get the case one day 😉