In my api controller action method. I am using ContentNegotation for Get Request. the code is :
IContentNegotiator negotiator = this.Configuration.Services.GetContentNegotiator();
ContentNegotiationResult result = negotiator.Negotiate(typeof(OfficeDetailsDto), this.Request, this.Configuration.Formatters);
if (result == null)
{
var responseErr = new HttpResponseMessage(HttpStatusCode.NotAcceptable);
throw new HttpResponseException(responseErr);
}
But now I want to create a BaseAPIController controller by inheriting ApiController and want to
override a base class's method to have the above code so that I don't have to write this code again and again in my every controller class. It will also make my controller action method thin.
Can anyone give me any suggestion or sample please.
None
0 Points
4 Posts
Override any Method of ApiController to avoid repeating code and create a BaseApi class to make a...
Mar 05, 2016 03:11 PM|neo.mn|LINK
In my api controller action method. I am using ContentNegotation for Get Request. the code is :
But now I want to create a BaseAPIController controller by inheriting ApiController and want to override a base class's method to have the above code so that I don't have to write this code again and again in my every controller class. It will also make my controller action method thin.
Can anyone give me any suggestion or sample please.
Contributor
2400 Points
669 Posts
Re: Override any Method of ApiController to avoid repeating code and create a BaseApi class to ma...
Mar 08, 2016 11:46 AM|PawanPal|LINK
Hi Neo,
You can use Action Fiters for that. Read below for more.
http://damienbod.com/2014/01/04/web-api-2-using-actionfilterattribute-overrideactionfiltersattribute-and-ioc-injection/
https://pawanpalblog.wordpress.com
www.jsengineeringworks.com