0

I am trying to get custom values for my site. So I've extended just the site.config with the "blubb" Attribute and "test12" value:

<site
      patch:before="site[@name='modules_website']"
      name="Shop-DE"
      hostName="sitecore.local"
      blubb="test12"
      targetHostName="sitecore.local"
      domain="sitecore.local"
      rootPath="/sitecore/content/SxpShop"
      startItem="/Startseite"
      virtualFolder="/"
      physicalFolder="/"
      language="en"
      database="web"
      allowDebug="true"
      cacheHtml="true"
      htmlCacheSize="50MB"
      filteredItemsCacheSize="10MB"
      enablePreview="true"
      enableWebEdit="true"
      enableDebugger="true"
      cacheRenderingParameters="true"
      renderingParametersCacheSize="10MB"/>
</sites>

In my code I am trying to get the custom value with:

var portal = Sitecore.Context.Site.Properties["blubb"];

but I get null because my new Attribute "blubb" is not in the "Properties" collection.

I am using Sitecore 9 update 2 and I've orientated me on this blog post: http://sitecoreblog.blogspot.com/2011/05/add-custom-property-to-site-node.html

  • 1
    I am guessing it might not be in the context site that you expect it to be. You might want to check what is the current context site using Sitecore.Context.Site.Name – Fredric Foo Mar 13 '19 at 6:26
  • @FredricFoo yes it seems to be the wrong site. Is there a standard way how to check what is the current context site? – squadwuschel Mar 13 '19 at 6:28
  • I had a similar need to have configuration specific to site context. This should do the trick if your SiteContext throws up the right value. – Ritwik Sen Sep 30 at 5:57
1

It seems to be that the Context.Site is not responding the right site context.

with this Extension it seems to work. But I don't know if this should be the prefered Solution.

   public static SiteContext CurrentSiteConfig(this Sitecore.Sites.SiteContext context)
    {
        if (Sitecore.Context.PageMode.IsExperienceEditor || Sitecore.Context.PageMode.IsPreview)
        {
            var url = System.Web.HttpContext.Current.Request.Url;
            var siteContext = SiteContextFactory.GetSiteContext(url.Host, url.PathAndQuery);
            return siteContext;
        }

        // standard context site resolution via hostname, virtual/physical path, and port number
        return context;
    }
| improve this answer | |
  • 1
    The reason you need to do this is, that the Sitecore sites (the Content Editor, the Experience Editor and so on) run in the context of the shell site. So one way or another, you will need to check for this. The code snippet seems ok for this task. – Mark Cassidy Mar 13 '19 at 9:25

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.