Sitecore Experience Editor with different Site context

Challenge:

In Multi-Site Sitecore solution we allow user to load any site in Experience Editor with any Sitecore Site URL. We also provide an option to the user to create Sites on the fly. The problem we were facing was during Experience Editor. In Experience Editor you can make use of query string and get the Item based on sc_itemid. That was working absolutely fine. Now we provided an option to a user in Ribbon to change the color. Every Custom Site that user creates on the fly – each have their own fields to change the color.  We were not getting the correct site because Webutil was providing the below information.

Sitecore.Web.WebUtil.GetRawUrl(): “/-/speak/request/v1/expeditor/ExperienceEditor.GenerateFieldUrl”

Speak Request URL: http://sc8.com:80/-/speak/request/v1/expeditor/ExperienceEditor.GenerateFieldUrl

Now in this request you don’t get sc_itemid – we wanted to get the actual item id (sc_itemid) based on the current Site which user has loaded in Experience Editor, so that we can show/load the correct option to change the color.

Solution:

HttpContext.Current.Request.UrlReferrer.Query

Result: “?sc_content=core&ribbonId=%7B570A52B6-6755-461A-8052-5B95EF766F74%7D&itemId=%7BD452060D-C194-433A-BA57-CA77E7C692C3%7D&deviceId=%7BFE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3%7D&database=master&mode=edit&url=%2F%3Fsc_mode%3Dedit%26sc_itemid%3D%7Bd452060d-c194-433a-ba57-ca77e7c692c3%7D%26sc_lang%3Den%26sc_ee_fb%3Dfalse&lang=en&pageSite=mysite”

By this, we parse query-string and get the itemid, based on which we fetch the required content from Sitecore. So whatever is the context site, we didn’t bother of because we are getting the item based on above solution.

If you know any other solution, please write in comments.

Thanks to Damini who worked on this issue.

Happy Sitecoring!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.