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
Languages.AlwaysStripLanguage = true
languageEmbedding=always
inlinkprovider
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
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
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)update all 4 site's
sitedefinition.config
file
And in option 2, the change in only at one place.
Which option would you suggest?