Last post Nov 29, 2016 09:13 PM by deepalgorithm
Nov 29, 2016 02:39 PM|sudip_inn|LINK
just saw a class called DelegatingHandler . please some one tell me what is the usage of
DelegatingHandler class ?
DelegatingHandler is specific to web api or it can be used for asp.net mvc too ?
just saw a code regarding usage of
public class ContentValidationHandler : DelegatingHandler
private static log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
var response = await base.SendAsync(request, cancellationToken);
Stream strea = new MemoryStream();
strea.Position = 0;
StreamReader reader = new StreamReader(strea);
String res = reader.ReadToEnd();
Log.Info("request content: " + res);
what the above code is doing tell me ?
DelegatingHandler used at client side or web api server side ?
Nov 29, 2016 03:08 PM|deepalgorithm|LINK
It's a message handler. And the process of chaining message message handlers together is a
Message handlers are good for for cross-cutting concerns that operate at the level of HTTP messages (rather than controller actions).
In order to create a custom handler, you have to inherit from DelegatingHandler and override SendAsync (which you are).
Your code sample is for the client.
ASP.NET MVC does not provide this extensibility point.
More info here:
Nov 29, 2016 07:44 PM|sudip_inn|LINK
do i need to work with DelegatingHandler at client side or server side ?
Nov 29, 2016 09:08 PM|deepalgorithm|LINK
You can implement a DelegatingHandler on the client as well. It depends on what your
Nov 29, 2016 09:13 PM|deepalgorithm|LINK
I've updated my answer and created a new answer for this question. Hope it helps.