We noticed the Application_Start in the Global asax is no longer hit after the upgrade to Sitecore 8.2.

Does anyone have an idea what may have caused this?

My global.asax.cs:

public class Global : Sitecore.Web.Application
{
    protected void Application_Start()
    {
        // some code
    }
}

Global.asax:

<%@ Application Codebehind="Global.asax.cs" Inherits="[namespace].Global" Language="C#" %>

Edit:

In order to be sure the Application_Start is not hit I did a few tests:

  • Added a System.Diagnostics.Debugger.Break();
  • Edited the Global.asax file while debugger was attached
  • Threw an exception

None of the above were successful.

The target framework is set to 4.6

  • Are you sure it's not hit? Can easily go wrong, if you're relying on attaching a debugger to see a breakpoint get hit. stackoverflow.com/questions/967813/… – Mark Cassidy Nov 8 '16 at 10:33
  • Yes, I added a System.Diagnostics.Debugger.Break() which did not work. Then changed the global.asax while the debugger was attached and even threw an exception to make sure it's not hit. – Nico Grms Nov 8 '16 at 10:36
  • 1
    Right. Hmm. And you've changed your build target to .NET 4.5.2? – Mark Cassidy Nov 8 '16 at 10:36
  • The target framework is set to 4.6 – Nico Grms Nov 8 '16 at 10:41
  • @NicoGeeroms You're probably not restarting the app completely. Detach the debugger, then stop the application pool in IIS, then start it again. See if Application_Start is executed then. Don't use exceptions to check if it's executed (you won't necessarily see them and the app will start anyway). Instead, use Debugger.Break() or write to a file on disk, or something similar. – Dmytro Shevchenko Nov 8 '16 at 10:51
up vote 25 down vote accepted

It is best practice to not modify the global.asax file. Best to use the Sitecore pipelines to accomplish the same task. This allows you to follow Helix more closely and makes upgrading the site simpler.

using System.Web.Mvc;
using System.Web.Routing;
using Sitecore.Pipelines;

namespace YourApp.Pipelines.Initialize
{
    public class RegisterApiRoutes : Sitecore.Mvc.Pipelines.Loader.InitializeRoutes
    {
        public override void Process(PipelineArgs args)
        {
           // app start here
        }
    }
}

Then your config

<pipelines>
  <initialize>
    <processor type="YourApp.Pipelines.Initialize.RegisterApiRoutes, YourApp" />
  </initialize>
</pipelines>

Other Global.asax functions https://laubplusco.net/global-asax-sitecore-pipelines/

  • This did indeed fixed it. Thanks! – Nico Grms Nov 8 '16 at 16:57
  • How one should decide which to use between Pipelines.Loader.InitializeAspNetMvc, Pipelines.Loader.InitializeControllerFactory, Pipelines.Loader.InitializeDependencyResolver, Pipelines.Loader.InitializeGlobalFilters, Pipelines.Loader.InitializeRoutes? Which gets executed first? – Francesco Gallarotti Nov 10 '16 at 9:48
  • 3
    You can see the order in /admin/showconfig.aspx. Look for the processors with the types you stated above. . Its InitializeAspNetMvc, InitializeGlobalFilters, InitializeDependencyResolver, InitializeControllerFactory and finally InitializeRoutes. Each processor assists in a different part of the MVC initialization. – Chris Auer Nov 10 '16 at 14:34

The Application_Start method of Sitecore.Web.Application has been made internal in 8.2 which is why you cannot override it and your method is not being hit.

internal void Application_Start(object sender, EventArgs args)
{
    ServiceLocator.MakeReadonly();
}

You will have to use the initialize pipeline as mentioned by dnstommy, which is also best practice.

  • Good to know! Thanks. – Srikanth Kondapally Nov 8 '16 at 14:25
  • 6
    Sitecore Support confirmed that making Application_Start internal is a bug and has been registered with reference #126372. – Nico Grms Nov 14 '16 at 15:00

You may need to check if your Global asax inherits from Sitecore.Web.Application

<%@ Application Codebehind="Global.asax.cs" Inherits="Sitecore.Web.Application" Language="C#" %>
  • 1
    Could you expand on this answer? Right now it doesn't really help with why this would fix the issue the question is asking. The answer should also contain some additional information that would make it stand out as a separate answer from the other answers (especially the one that was marked as the fix) – Patrick Barron Dec 4 '17 at 15:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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