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.
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]
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With