title: asp.net core route specific middleware
body: <p>I was working with KOA 2.0 and started to test asp.net core. But can't find a way to handle request/url specific middleware</p>
  
  <p>Say in Koa, with router I can achieve the below:</p>
  
  <pre><code>.post("/api/v1/user", Middleware1, Middleware2, RequestValidationMiddleware, SpecificAction);
  .get("/api/v1/user", Middleware1, Middleware2, RequestValidationMiddleware, SpecificAction1);
  .post("/api/v1/role", Middleware1, Middleware4, RequestValidationMiddleware2, SpecificAction2);
  </code></pre>
  
  <p>How to achieve it with asp.net core?</p>
  
  <p>Tried the below:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
      }
  
      //app.UseApiLog();
      app.Map("/api", ApiLogApps);
      app.Map("/exlog", ExceptionLogApps);
  
      //app.UseMvc(routes =&gt;
      //{
      //    routes.MapRoute(
      //                    name: "default",
      //                    template: "apilog/{controller}/{action}");
      //    routes.MapRoute(
      //                    name: "default2",
      //                    template: "exlog/{controller=Home}/{action=Index}/{id:int}");
      //});
  }
  
  private static void ApiLogApps(IApplicationBuilder app)
  {
      //app.Run(() =&gt; )
      app.UseApiLog();
      app.UseMvc();
  }
  </code></pre>
  
  <p>And in controller I have</p>
  
  <pre><code>[Route("api/[controller]")]
  public class ValuesController : Controller
  {
      // GET api/values
      [HttpGet]
      public IEnumerable&lt;string&gt; Get()
      {
          return new string[] { "value1", "value2" };
      }
  
      // GET api/values/5
      [HttpGet("test/get/{id}")]
      public string Get(int id)
      {
          return "value";
      }
  }
  </code></pre>
  
  <p>But I am lost here.</p>
  
  <p>What I want is, I want to have DataValidation to be handled in a middleware - that forces me to have per url (almost) specific middleware.</p>
  
  <p>PS - I know, model validation can be done in action, but I don't want that.</p>
  
  <p>Thanks in advance for your help :)</p>