Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore - Is this an 'internal' site?

Tags:

sitecore

Is there an easy way to determine if a site is one of Sitecore's own sites?

Basically, what I'm looking for is shorthand for:

var sitenames = new string[] {"admin","shell","login","service"}; // etc.

if(!sitenames.Contains(Sitecore.Context.Site.Name))
    //do stuff

I don't see anything in the SiteContext or SiteInfo classes that look helpful for this.

I'm quite happy to write this functionality myself. I just want to make sure it's not already hidden away somewhere.

like image 696
Martin Davies Avatar asked Jan 18 '14 09:01

Martin Davies


2 Answers

Looking at the Site definitions in the web.config all Sitecore internal things have the domain property set to Sitecore.

So basically something like this:

if (Sitecore.Context.Site.Domain != Sitecore.Security.Domains.Domain.GetDomain("sitecore"))
{
    // [Do stuff here]
}
like image 144
Trayek Avatar answered Sep 30 '22 13:09

Trayek


Off the back of @Trayek's answer I wrote this extension method, which works nicely.

namespace Extensions
{
    public static class SiteContextExtensions
    {
        public static bool IsInternal(this SiteContext siteContext)
        {
            return siteContext.Domain.Name == "sitecore";
        }
    }   
}

Usage:

if(!Sitecore.Context.Site.IsInternal())
    // Do stuff
like image 25
Martin Davies Avatar answered Sep 30 '22 13:09

Martin Davies