title: Conditional configuration to ASP.NET Core exceptionhandling middleware
body: <p>I'm invoking same ASP.NET Core 3.1 middleware but with different options. For instance my <code>Startup.Configure()</code> looks like:</p>
  <pre><code>var exceptionHandlerOptions = new ExceptionHandlerOptions();
  app.UseWhen(context =&gt; context.Request.Path.StartsWithSegments(&quot;/api&quot;), appBuilder =&gt;
  {
    // Error in WebApi controller
    exceptionHandlerOptions.ExceptionHandlingPath = &quot;/api-exception-handler&quot;;
    appBuilder.UseMiddleware&lt;exceptionhandlermiddleware&gt;(Options.Create(exceptionHandlerOptions));
  });
  app.UseWhen(context =&gt; !context.Request.Path.StartsWithSegments(&quot;/api&quot;), appBuilder =&gt;
  {
    // Error in Mvc controller
    exceptionHandlerOptions.ExceptionHandlingPath = &quot;/mvc-exception-handler&quot;;
    appBuilder.UseMiddleware&lt;exceptionhandlermiddleware&gt;(Options.Create(exceptionHandlerOptions));
  });
  </code></pre>
  <p>However, I can't make it to run properly. The <code>ExceptionHandlingPath</code> is always <code>&quot;/mvc-exception-handler&quot;</code>.</p>
  <p>P.S. I trimmed my example for simplicity here. My real implementation is bit different though e.g. I have an extension method on IAppBuilder to wrap UseWhen of Exceptionhandlermiddleware.</p>