title: Why is the Configuration method of the SignalR Startup class invoked twice
body: <p>I am running some initialization code in the Startup class used by SignalR. The code is invoked in the Configuration method (this is in as ASPNET MVC app).</p>
  
  <p>The initialization code needs to run exactly once and is placed in the <code>Configuration(IAppBuilder app)</code> method of the Startup class like so: </p>
  
  <pre><code>public void Configuration(IAppBuilder app)
          {                
              //Call some custom pre initialization code
              ConfigureAuth(app);
              //Call some custom post initialization code
          }
  </code></pre>
  
  <p>I noticed that the <code>public void Configuration(IAppBuilder app)</code> method is invoked exactly twice on startup of the app.
  <strong>The question is why?</strong></p>
  
  <p>Is this the right place to run the pre and post signalr initialization code or should this occur at a different location. My need is to ensure that the pre and post custom initialization code runs exactly once.</p>
  
  <p><strong>UPDATE:</strong>
  Following is the Call Stack leading upto the second call to "Configuration". The call seems to be happening on a background thread momentarily after the web app renders the default page.</p>
  
  <pre><code>&gt;   MyWebApp.dll!MyWebApp.Startup.Configuration(Owin.IAppBuilder app) Line 45   C#
      [Native to Managed Transition]  
      Microsoft.Owin.Host.SystemWeb.dll!Owin.Loader.DefaultLoader.MakeDelegate.AnonymousMethod__b(Owin.IAppBuilder builder)   Unknown
      Microsoft.Owin.Host.SystemWeb.dll!Owin.Loader.DefaultLoader.LoadImplementation.AnonymousMethod__0(Owin.IAppBuilder builder) Unknown
      Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint.AnonymousMethod__0(Owin.IAppBuilder builder) Unknown
      Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(System.Action&lt;Owin.IAppBuilder&gt; startup)  Unknown
      Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(System.Action&lt;Owin.IAppBuilder&gt; startup)  Unknown
      Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint()    Unknown
      mscorlib.dll!System.Threading.LazyInitializer.EnsureInitializedCore&lt;System.__Canon&gt;(ref System.__Canon target, ref bool initialized, ref object syncLock, System.Func&lt;System.__Canon&gt; valueFactory) Unknown
      mscorlib.dll!System.Threading.LazyInitializer.EnsureInitialized&lt;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineBlueprint&gt;(ref Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineBlueprint target, ref bool initialized, ref object syncLock, System.Func&lt;Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineBlueprint&gt; valueFactory)   Unknown
      Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(System.Web.HttpApplication context) Unknown
      System.Web.dll!System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(System.IntPtr appContext, System.Web.HttpContext context, System.Reflection.MethodInfo[] handlers)  Unknown
      System.Web.dll!System.Web.HttpApplication.InitSpecial(System.Web.HttpApplicationState state, System.Reflection.MethodInfo[] handlers, System.IntPtr appContext, System.Web.HttpContext context) Unknown
      System.Web.dll!System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(System.IntPtr appContext, System.Web.HttpContext context)    Unknown
      System.Web.dll!System.Web.Hosting.PipelineRuntime.InitializeApplication(System.IntPtr appContext)   Unknown
      [AppDomain Transition]  
  </code></pre>