From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Creating a custom message handler

Creating a custom message handler

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

Creating a custom message handler

- [Instructor] We are going to create a custom handler that we can use to validate the request. So for that let us go to Visual Studio. In here, go to Solution Explorer and, under the WebApi .DI project, we are going to create a new folder. So Add, then NewFolder. Let us name this folder CustomHandlers and let us create our first handler, so Add, Class. Let us name this handlers Request Validate Handler. Now, to create a custom handler, we need to inherit from the base class delegating handler, so Delegating Handler. Let us import the necessary name space, which is the System.Net.Http, and now let us override the method that we need. For that, we write in here override space and we get five options. We are going to use the SendAsync method, which we see that it takes two parameters. The first one is the request parameter of type HttpRequestMessage and the other one is the cancellation token.…

Contents