MVC Routes, Redirection and Sitecore

I know there has been a loooong pause after my last series, past few months have been a crazy head down time doing not so Sitecorish stuff and more on API front.   I like to blog something new I learnt that is totally Sitecore related or affiliated, so, I had to resist the temptation to blog something that is not so uncommon or known by most of us.

Last week I got a kick of something that should be or was assumed to be straight forward, but, just stumped me that I did not know this before. 🙂

In most of the ideal projects of Sitecore, even if they are MVC driven, we do not need to use the custom routes for the most part.  The default one should usually be good enough and if you did have api specific post/get calls that fall through controller that should also have been working fine with out any additional configuration.

So, what if your implementation calls for rendering a specific content item based on URL specific to your needs.  Well, in this case you will see yourself in some trouble if you have patched your Redirection logic to ItemResolver or your customItemResolver for instance.   The problem is the page does not render and correct controllers do not hit, my pages were literally blank leading me no where, I was seeing a ghost in-front of me. lol

It took me some time to figure out what just happened to a page that was working literally before this build, I had to backtrack my steps and realized I fixed a configuration that has now added a new patch to my ItemResolver.  I could have dropped it, but, we all need that Redirect patch don’t we? The marketing and content authors love it and absolutely need it.   So, I had no option but to fix it.

So, to fix this first ensure your order is correct that is –

Item Resolver -> Your Custom Item Resolver -> No sitecore item found -> Redirect Manager Patch -> Still nothing -> Page Not Found Handling

Now, above is typical intuitive flow, but, do understand all projects and baseline could be different and hence you will have to ensure the order is correct according to your application.

My order seems correct, but, still I see the ghost page.  Why ? Why?

So, here is why, if you see closely on your showconfig.aspx, you will see MVC Routing is happening after the above steps noted as we typically end up patching our Redirect logic to ItemResolver leading to issues.  Now, there are two ways you can fix these issues now that you know the cause.

  1. In your custom item resolver, ensure you are configuring and adding code to resolve item from MVC Routes.  It should be pretty straight forward and there should be bunch of examples I am sure to get this done with lot of duplication of code based on how many routes you have actually got going on your RouteConfig.cs
  2. You could also save your self some copy paste effort(I usually make tons of mistakes when I do copy paste, it makes me lazy. 😉 ) and patch your Redirect logic to right after MVC pipelines.  Below is a screenshot of how that may look like –

Order_redirect

Hopefully it will save you some time thinking why your custom routes are not working when redirect is used along side of ItemResolver.  Happy Sitecoring people!

I promise to blog back pretty soon this time and I am super excited to meet all my favorite people in Orlando, Florida for the symposium.  This is my first symposium attendance and being an MVP this year as well is a total icing on the experience. 🙂

Sitecore Sharing! Same Same, but, Here There

wild card

Happy New year to one and all!  It is always an awesome feeling to welcome the new year and leave behind what was done in previous year in memories. The beauty of memories, they can be good, bad or worse and everything in between, but, regardless, we are set to move forward to make new memories this year, new learning and potentially reach new heights. 🙂

I was waiting to find perfect topic for my first blog this new year.  I think I just found one, so, I was working for one of our clients who wanted to see, how many options do they have to share content across multiple sites on a Multi site single sitecore instance.   They currently use wildcard mechanism with multiple sites configured to have different root paths, but, the content resides in one area regardless of which site the piece of content belongs to.

Why would they want to see other options is that they strongly believed that content structure they use the problem for performance issues, which, well could be legit as a risk that comes with meddling any pipeline while not being cautious.

Below are the three options I could find from brainstorming, research and asking other folks to top off the wild card approach they already have in play.  Do you all have any other options that you have used in the past, if yes, would love to hear more.  Drop in a comment!

  1. Hybrid tree approach :  This is basically going with shared root path approach if the page tree is consistent and is exactly similar.  If the page content is going to be different, then, for that specific site configuration you will need to define a different root path and main content in a separate tree altogether.
  2. Clones:  I have seen many old implementations that would go this route in shared content situations, but, struggled a lot with intuitive changes and workflow, publish issues faced by content authors.
  3. MVC Routing :  If your application is using MVC, then, this could be one decent solve instead of wild card and ten other pipelines being affected to support wild card.  Note though, when using some of this as an experiment the routing code was literally running for every module when a breakpoint was placed.  Pay close attention to where this logic is being run and how performance efficient this is.