ASP.NET Core ApiVersioning change middleware hierarchy -


i have problem middleware hierarchy. created simple web api 1 controller/action

[route("api/v1/values")]   public class valuescontroller : controller   {     // api/v1/values/5     [httpget("{id}")]     public async task<iactionresult> get(string id)     {       return await task.run<iactionresult>(() =>       {         if (id == "nf")         {           return notfound();         }          return ok($"value: {id}");       });     }   } 

i configured routing use mvc if match or write default response if not.

app.usemvc();  app.use(async (context, next) => {   await context.response.writeasync("default"); }); 

and works great, below can see sample requests/responses:

/api/v1/values/1 -> 200, body: "value: 1" /api/v1/values/nf -> 404 /api/v1/values -> "default" 

great, added apiversioning, controller looks this:

[apiversion("1")] [route("api/v{version:apiversion}/values")] public class valuescontroller : controller 

and added startup : services.addapiversioning();. break routing completely, each request response "default", when remove last app.use, routing works fine values controller, don't have default middleware. know how can responses same prevously, apiversioning?

try this.

[apiversion("1.0")] [route("api/v{version:apiversion}/foo")] public class foocontroller {} 

and in startup class

 public void configureservices(iservicecollection services)         {             services.addapiversioning(options =>             {                 options.reportapiversions = true;                 options.assumedefaultversionwhenunspecified = true;                 options.defaultapiversion = new apiversion(1, 0);             });         } 

i have tried , worked me.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -