2

I am trying to build asp.net core WEB API service, wherein i want to send consistent response with a similar structure returned for all requests.

In earlier version of WEB API, we had DelegatingHandler ,using this we could intercept response and add metadata information into response.

Something of what following URL explained : https://www.devtrends.co.uk/blog/wrapping-asp.net-web-api-responses-for-consistency-and-to-provide-additional-information

I tried OWIN Middleware , but not getting the result.

Is there any way of achieving it in core WEB API.?

Thanks in advance.

ravibhat
  • 811
  • 1
  • 7
  • 19
  • Delegating handler have been replaced by Middleware in .Net-Core. You said you tried owin middleware. core follows the same model. Show what you tried and were having difficulty with. Maybe we can guide you to a solution. – Nkosi Jun 10 '17 at 00:23
  • Thanks, i was wrong while updating Response back to context. – ravibhat Jun 10 '17 at 16:30
  • Glad you eventually figured it out. If you have solved the issue either add it as a self answer to benefit others or delete the question if you believe it will be of no benefit to others in the future. – Nkosi Jun 10 '17 at 16:33

2 Answers2

2

Don't know what exactly you have tried, but in ASP.NET Core the middleware is exactly what you need, as:

Middleware is software that is assembled into an application pipeline to handle requests and responses. Each component chooses whether to pass the request on to the next component in the pipeline, and can perform certain actions before and after the next component is invoked in the pipeline.

Migrating HTTP Modules to Middleware section in documentation explains the difference between request pipelines in ASP.NET Core and the previous versions and should help you to understand how to write middleware that will conduct in a way you need.

Also look into related SO question: Registering a new DelegatingHandler in ASP.NET Core Web API

Set
  • 47,577
  • 22
  • 132
  • 150
0

Can we implement something similar to Interceptors in ASP.net Core

In ASP.NET core for every request want to make a call to other external service and read the dynamically changing authentication details like username and password and store/update it in app secrets to send the down stream service. Tried with Middleware but which is making call to that external service only once and inserting it in app secretes dictionary. If the password changed in that external service which is not reflecting because the middleware pipeline not making the call always to external service.

Interceptors reference : https://www.c-sharpcorner.com/article/interceptors-an-important-feature-of-http-client/

amshekar
  • 31
  • 2
  • 7