Page Inspector causing multiple calls to HttpApplication : Application_Start in Web Site Projects
I had a mysterious problem receiving multiple calls to Application_Start on almost every HTTP request to IISExpress. Upon further investigation, I found Visual Studio 2012's Page Inspector causing the problem.
Inside the default machine's Web.config located at: Windows\Microsoft.NET\Framework\v4.0.30319\Config, XPath: \System.Web\compilation\assemblies has an assembly "Microsoft.VisualStudio.Web.PageInspector.Loader", which dynamically loads itself via [assembly: PreApplicationStartmethod(typeof(RuntimeLoader),"PreApplicationStart"] attribute.
The ASP.NET BuildManager's hash of the compiled web site project kept changing upon the first & subsequent request to IISExpress. Somehow the dynamically loaded PageInsepctor.Runtime caused the HttpApplication to shutdown, startup, in an oscillating fashion (hence, the mulitiple Application_Start calls) as requests were being processed. Specifically, Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.
SelectionMappingExecutionListenerModule.PreApplicationStart()'s call to BuildManager.AddCompilationDependency() caused root compilation hash to change.
Disabling and removing Microsoft's Page Inspector feature removed the restarting interference. Here's how to remove the entire feature from your project:
Disable Visual Studio 2012 Page Inspector
To disable visual studio Page Inspector remove the assembly inside your Web.config located in configuration/compilation/assemblies:
- <compilation debug="true" targetFramework="4.5">
- <remove assembly="Microsoft.VisualStudio.Web.PageInspector.Loader,
Alternatively, you can add this to your appSettings:
- <add key="PageInspector:ServerCodeMappingSupport" value="Disabled" />
Hope that helps,