Pipelines - remember the big picture

Sitecore pipelines are great. With them you can relatively easily add and remove functionality as you wish. Pipelines like httpRequestBegin, httpRequestProcessed and mvc.beginRequest are also really useful if you need some logic to run on a page load that shouldn't really be part of a rendering. This could be anything from login checks to updating the way 404 pages are returned. However you do need to remember the big picture of what you are changing.

Pipelines don't just effect the processes of the website your building, Sitecore uses them too. That means when you add a new processor to the httpRequestBegin pipeline, that's going to effect every request in the admin CMS too. Just checking the context item also isn't enough as some things. e.g. opening a node in a tree view, will have the context of the node you clicked on!

Adding this snippet of code to the beginning of your process should keep you safe though.

using Sitecore.Diagnostics;
using Sitecore.Pipelines.HttpRequest;
using Sitecore;
using Sitecore.SecurityModel;

namespace CustomPiplelineNamespace
{
  public class CustomPipeline : HttpRequestProcessor
  {
      public override void Process(HttpRequestArgs args)
      {
          //Check args isn't null
          Assert.ArgumentNotNull(args, "args");
          //Check we have a site
          if (Context.Site == null)
              return;
          //Check the sites domain isn't one for sitecore
          if (Context.Site.Domain != DomainManager.GetDomain("sitecore"))
              return;
          //Check that we're not in a redirect
          if (args.Url.FilePathWithQueryString.ToUpperInvariant().Contains("redirected=true".ToUpperInvariant()))
              return;
          //Check that we're not in the page editor
          if (Context.PageMode.IsPageEditor)
              return;

          // DO CODE
      }
  }
}