I am trying to attach a handler/code when the Sitecore web application instance is starting up.

What event is triggered when the application instance starts?

  • Can you expand on your question to make it clearer please? What do you mean by "instance" ?
    – Richard Seal
    Commented May 15, 2017 at 17:38
  • Instance means Sitecore Web site Instance
    – Tony
    Commented May 15, 2017 at 17:39
  • Ok - so the application start is very different to a session start (from your question title) - which do you need?
    – Richard Seal
    Commented May 15, 2017 at 17:40
  • application start I think is what I am looking for.
    – Tony
    Commented May 15, 2017 at 17:45

2 Answers 2


Ok - for attaching code to when the application starts, you have a couple of options.

Initialize Pipeline

The standard way to do this is via the Initialize pipeline. Create yourself a new processor class. It does not need to inherit from anything, but must have a public method called Process that takes a PipelineArgs object.


public class DoSomethingOnStartup
    public void Process(PipelineArgs args)
        // Add your code here

You would then patch that into Sitecore via an include file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <processor type="MyNamespace.DoSomethingOnStartup, MyAssembley" />


This is a slightly less Sitecorian way of doing it, but does work. Add WebActivatorEx to your project from NuGet.

Create your class and add it to the App_Start folder and add the WebActivatorEx attribute:


using System.Diagnostics;
using System.Web.Mvc;
using System.Web.Routing;

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(TestWebApp.TestStartupCode.MyStartupCode), "Start",Order = 1)]

namespace TestWebApp.TestStartupCode
    public static class MyStartupCode
        public static bool StartCalled { get; set; }

        public static void Start()
            StartCalled = true;

Which to use?

It really is up to your requirements, both methods work. Using the Sitecore pipeline, means you can get access to other data in the Sitecore initialize pipeline and also you can position your startup code to run at a specific point in the start up. Its the option I would take 95% of the time.

If for some reason you can't or don't want to rely on the Sitecore pipeline, WebActivator is a good alternative. E.g if you are writing a component and don't have access to modify any configuration.

What about the Global.asax

Historically, this was also an option, but as this has now been made private by Sitecore, it is not a viable option anymore.


Create your own Global.asax codebehind inheriting the sitecore one.

There you can put an event handler for the Application_Start event to execute your custom code.

  • Don't do this anymore - it will not work with later versions of Sitecore.
    – Richard Seal
    Commented Jun 5, 2017 at 16:49
  • Yes. Do not change OOTB Sitecore files unless absolutely necessary. The best practices and recommended answer to this is Richard's - using the Initialize Pipeline - that is exactly what it is for. Commented Oct 26, 2017 at 13:43
  • The class Sitecore.Web.Application that the default Global.asax file uses has a virtual method for Application_Start, so yes, you can override it and it will work - I got the 8.2 update-4 version and I'm doing this. I totally agree not to mess with OOTB sitecore files but it's the Global.asax file that we're talking about. It would be dumb of Sitecore to completely own this file and not let developers extend it for their own implementation.
    – Jeff Sulit
    Commented Oct 31, 2017 at 22:25
  • If you are worried about upgrade paths, I urge against this approach. Even on older versions it was a pain going between versions where the way Sitecore was using Global.asax was changing underneath you. It makes life easier long term to avoid this pain. Commented Sep 24, 2019 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.