Wildcards – Resolving Item and MVC in sitecore

PageItemPipelines

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 :

 

 

And in this code specifically

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).

 My solution

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).

Thanks to Mike Edwards(@mikeedwards83) and Kamruz Jaman(@jammykam) for helping me on that one !

And I hope it will helps you if you get the case one day 😉

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *