Slow start up of an ASP.NET MVC app is very frequent and can be caused my multiple factors. It’s not that easy to identify and fix them, but here’s a couple of hint / tools that can help troubleshooting and hopefully accelerate startup time.
Third party libraries trough WebActivator
ASP.Net has a mechanism that allow third party libraries to register automatically when application is started a runtime.
These processes will usually register using one of the following attributes
[assembly: WebActivatorEx.PostApplicationStartMethod (typeof(MyNamespace.SomeType), “Args”)]
[assembly: WebActivatorEx. PreApplicationStartMethod (typeof(MyNamespace.SomeType), “Args”)]
[assembly: WebActivatorEx. ApplicationShutdownMethod (typeof(MyNamespace.SomeType), “Args”)]
The one we are interested in here are PostApplicationStartMethod and PreApplicationStartMethod. You can indentify them easily using the vs. search window (CTRL+SHIF+F) and select “Find in solution” then search for both PostApplicationStartMethod and PreApplicationStartMethod.
You can then try and comment them to benchmark how much time is consume by these web activators to register custom libraries.
Your application should contain a global.asax file where you will find the Application_Start method. This is where you initialize configurations for your application and startup configurations. By default you should Route and bundle configurations.
Good practice is to keep this method lean and avoid adding to much implementation to it.
If your web project contains lots of areas and views, your application will require some time on first start to compile all the views using the razor engine. You can easily eliminate this compile time by precompiling your views at built time. I have wrote an article about it here :
Disabling bundling in debug mode can accelerate your startup time when you are in development. This can be done trough the BundleConfig.cs file,by simply addind this at the beginning of the registerBundles method
BundleTable.EnableOptimizations = false;