0

i want to process certain operation at 'httprequestbegin' pipeline in live web page (CM or CD) i.e.

  • notequals to PageEditor,
  • notequals to ExperienceEditor,
  • notequals to ContentEditor,
  • notequals to Preview

After some analysis & references from this link Most reliable way to detect if running in live site?

My code snippet looks like

if (Sitecore.Context.PageMode.IsNormal 
&& !Sitecore.Context.Site.Name.ToLower.Equals("shell"))
{
//Do task here
}

Question: since we have default websites like shell,login,services,scheduer,system etc, do i need to include all the sites in the above condition to get out of default websites provided by sitecore. I have noticed 'service' website is triggering a request which would bypass the above condition.

Any inputs on this please.

3

You may add the following settings in a configuration file:

<settings>
    <!-- Sites to ignore by custom processors -->
    <setting name="SitesToIgnoreByCustomProcessors" value="shell,login,admin,service,scheduler,system,publisher,modules_shell,modules_website"/>
    <setting name="LinksToIgnoreByCustomProcessors" value="-/media/,~/media/,/layouts/system/visitoridentification,/api/sitecore,-/speak,-/item,/sitecore"/>
</settings>

All the sites and links that you do not want to process can be included in the above settings. The you perform a check as follows:

    var settings = Settings.GetSetting("SitesToIgnoreByCustomProcessors", string.Empty)
            .ToLowerInvariant()
            .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
            .ToList<string>();

//Request to perform when site is not Equal to sitecore default sites. (EDITED)
    if (Sitecore.Context.PageMode.IsNormal && !settings.Contains(Context.Site.Name.ToLowerInvariant()))
    {
        //Do task here
    }
2

All the internal sites have domain property set to sitecore so you could check the domain property of the context site:

if (Sitecore.Context.Site.Domain != Sitecore.Security.Domains.Domain.GetDomain("sitecore"))
{
    // [Do stuff here]
}

You can find more details on this previous answer from @Trayek. Also note the extension method in the other answer from @MartinDavies

  • but modules_website's domain name is 'extranet'. how would that be ignored ? correct me if iam wrong. – Balaji Kuppuswamy Feb 6 '17 at 12:36
0

Since we are using multi-tenant solution, I'm able to achieve this by below code. i.e. verifying domain equals to "extranet" & hostname not equals to null/empty.

 if (Sitecore.Context.PageMode.IsNormal 
          && GetSites().Where(x =>x.Name.ToLower()
            .Equals(Sitecore.Context.Site.Name.ToLower()))
{
         //Do task here
}



 private List<SiteInfo> GetSites()
    {
        List<SiteInfo> sitesInformation = Factory.GetSiteInfoList();
        if (sitesInformation != null && sitesInformation.Count > 0)
        {
            return sitesInformation.Where(s => s.Domain != null 
                     && s.Domain == "extranet" 
                     && !string.IsNullOrEmpty(s.HostName)).ToList();
        }

        return null;
    }

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.