title: .MapWhen executing for all calls
body: <p>I have a large already running application built on .net core 1.0.4. I have a need to add a micro api to this application, and am attempting to integrate a fairly simple http basic auth middleware into the pipeline <strong>only</strong> for calls to the api controller. </p>
  
  <p>In my <code>startup.cs</code>configure method, I have the following. </p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {            
          //run basic auth only on API calls           
          app.MapWhen(context =&gt; context.Request.Path.StartsWithSegments("/api", StringComparison.OrdinalIgnoreCase), appBuilder =&gt;
          {
              app.UseMiddleware&lt;BasicAuthenticationMiddleware&gt;();
              app.UseMvc();
          });
  
  
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler("/site/error");
          }
  
          app.UseStaticFiles();            
  
          app.UseIdentity();
  
          app.UseDefaultFiles();
          app.UseStatusCodePages();            
  
          app.UseSession();
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Site}/{action=Login}/{id?}");
          });
  
  
      }
  </code></pre>
  
  <p>It's my understanding that the pipeline would branch for all calls that start with /api into the Basic middle ware. My issue is that with this code, ALL calls regardless of the path are hitting the <code>.MapWhen</code> path, and essentially breaking the entire site. </p>