4

I have implement micro-site solution in Sitecore 8.1 as described in below post Set up microsites in Sitecore 8.1

but we are not getting correct site context for each individual micro-sites. Following code is being used to get site context:

var url = System.Web.HttpContext.Current.Request.Url;
var siteContext = Sitecore.Sites.SiteContextFactory.GetSiteContext(url.Host, url.PathAndQuery);
string siteSettingsRoot = siteContext.Properties["SiteSettingsNode"].ToString();

and below is sitedefinition for micro-sites

name="micrositemainone" hostName="microsite.mysite.com" virtualFolder="/company1" startItem="/Home"
physicalFolder="/company1" rootPath="/sitecore/content/Site/Microsites/company1" SiteSettingsNode="/sitecore/content/Site/Microsites/company1/Site Settings"

name="micrositemain" hostName="microsite.mysite.com" virtualFolder="/"  startItem="/Home"
physicalFolder="/" rootPath="/sitecore/content/Site/Microsite/Main"  SiteSettingsNode="/sitecore/content/Site/Microsites/Main/Site Settings"

When I browse http://microsite.mysite.com/en/company1 it shows content specific to company1 but it returns SiteSettingsNode of micrositemain site not micrositemainone In this case I should get sitecontext of micrositemainone. Looks like need to change in code where I access Sitecore context.

Note: we have two settings

  1. Languages.AlwaysStripLanguage = true

  2. languageEmbedding=always in linkprovider element

because we already have running live site, so I can't change these for ex: www.mysite.com/en www.mysiteca.com/en www.mysiteca.com/fr-ca

UPDATE: 05-08-2017

If I have virtualFolder="/company1" & physicalFolder="/company1" in sitedefinition see below

enter image description here

As we can see /en/ is already added in as prefix that's why might be If I update both virtualFolder & physicalFolder value to "/en/company1" I got 404 page

UPDATE: 05-09-2017

Option 1:

Ok so I changed Languages.AlwaysStripLanguage value to false with following settings for micro-sites:

virtualFolder="/en/company1"

physicalFolder="/en/company1"

and now I'm getting correct sitecontext for each microsites but getting problem with other 4 sites i.e. If I browse http://mysite.com & http://mysiteca.com I got following error message:

This page isn’t working
ERR_TOO_MANY_REDIRECTS

to load other sites properly I updated virtualFolder="/en" & physicalFolder="/en" in all 4 sites's sitedefinition.config file.

Option 2

I kept virtualFolder="/company1" & physicalFolder="/company1" as it is for micro-sites but to get correct site context I made below change in function:

 public static Sitecore.Sites.SiteContext CurrentSiteNode
        {
            get
            {
                var url = System.Web.HttpContext.Current.Request.Url;
                var siteContext= Sitecore.Sites.SiteContextFactory.GetSiteContext(url.Host, url.PathAndQuery);
                if (siteContext.StartPath != null && siteContext.StartPath.Contains("Microsites") && url.PathAndQuery.Split('/').Length > 2)
                {
                    var currentsite = "/" + url.PathAndQuery.Split('/')[2];
                    return Sitecore.Sites.SiteContextFactory.GetSiteContext(url.Host,currentsite); // currentsite = company1 & url.Host = microsite.mysite.com
                }

                return siteContext;
            }
        }

So in option 1 I have to

  1. update Languages.AlwaysStripLanguage = false (I'm not sure do I really have to make this change because it's value is trued from the beginning of the project)

  2. update all 4 site's sitedefinition.config file

And in option 2, the change in only at one place.

Which option would you suggest?

5

The reason why you are receiving the SiteContext as micrositemain is because url.Host will return microsite.mysite.com.

Please see updated SiteDefinition below:

name="micrositemainone"
hostName="microsite.mysite.com" 
virtualFolder="/{language_here}/company1" //ex: /en/company1
startItem="/en/Home"
physicalFolder="/{language_here}/company1" 
rootPath="/sitecore/content/Site/Microsites/company1" 
SiteSettingsNode="/sitecore/content/Site/Microsites/company1/Site Settings"

name="micrositemain" 
hostName="microsite.mysite.com" 
virtualFolder="/"  
startItem="/Home"
physicalFolder="/" 
rootPath="/sitecore/content/Site/Microsite/Main"  
SiteSettingsNode="/sitecore/content/Site/Microsites/Main/Site Settings"

UPDATE

I have tested the above locally and saw that you need to update the setting Languages.AlwaysStripLanguage to false and add the above changes to the SiteDefinition.config.

Based on your question updates, I would suggest to manage it through the code, which is, option 2. The reason because you will have more control of it.

| improve this answer | |
  • I tried adding /en/ in virtualFolder/physicalFolder but after that change when I browsed microsite.mysite.com/en/company1 site it give me 404 error.... – Sukhjeevan May 8 '17 at 14:56
  • For micro-site we are using only English language so I'm using only /en I got below 404 URL after I browsed that ( microsite.mysite.com/en/company1 ) 404 URL --> microsite.mysite.com/en/… As per this post( hishaamn.wordpress.com/2016/12/22/… ) I was supposed to make two edits( Linkprovider & StripLanguage settings ) but I didn't make and I explained the reason in post at the bottom. – Sukhjeevan May 8 '17 at 16:01
  • fyi These sitedifinition doesn't have language attribute because none of other have this attribute... as you can see in 404 URL it's does have &site=micrositemain Do we need to do anything in micrositemain sitedefinition – Sukhjeevan May 8 '17 at 16:15
  • In the virtualFolder and physicalFolder just add the language. Example: /fr-ca/company1 – Hishaam Namooya May 8 '17 at 16:21
  • but why should I add this because I don't any any content for fr-ca in language It contains only en content...If I'm not mistaken – Sukhjeevan May 8 '17 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.