Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have below controller structure -
1. ValuesController : Controller
2. ValuesV2Controller : ValuesController 
3. ValuesV3Controller : ValuesV2Controller 
4. ValuesV4Controller : ValuesV3Controller
All controllers having one common method Get(Type value); to get a particular record. Type of value differs in every controller.

I have implemented versioning in ASP.NET Core Web APIs with Microsoft.AspNetCore.Mvc.Versioning Nugget.

In startup > Configure services; included below set of code :
C#
services.AddApiVersioning(o =>
        {
            o.ApiVersionReader = new HeaderApiVersionReader("x-lz-api- 
version");
            o.DefaultApiVersion = new ApiVersion(1, 0);
            o.ReportApiVersions = true;
            o.AssumeDefaultVersionWhenUnspecified = true;
         });
When we invoke V1, V2, V3 APIs then it gives 500 not found an error, specifically for Versioning performed with custom Header.

Tried out below possible solutions: 1. Making base class virtual and overriding derived classes from them, but as type differs, it doesn't work. 2. This problem doesn't occur for URL versioning, this is very specific to custom header versioning.

What I have tried:

Tried out below possible solutions:
1. Making base class virtual and overriding derived classes from them, but as type differs, it doesn't work.
2. This problem doesn't occur for URL versioning, this is very specific to custom header versioning.
Posted
Updated 14-May-19 1:07am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900