From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

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

X-HTTP-Method-Override header

X-HTTP-Method-Override header

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

X-HTTP-Method-Override header

- [Instructor] In Web API, we can also create custom handlers that can be used to override certain methods. This is useful for clients that cannot send certain HTTP types. So instead, the client sends a POST request and sets the X-HTTP-Method to the desired method. So let us now go to Visual Studio and create the Method-Override handler. In here, go to Solution Explorer, then to CustomHandlers folder, and add a new class. We are going to name this handler MethodOverrideHandler. We have set that to create a custom handler, we need to inherit from the base class DelegatingHandler. And let us import the necessary namespace which is the System.Net.Http. Now, next, we are going to override the SendAsync method but before we make any changes in this method, we are going to define the methods that we can override and the header. So let us write in here readOnly because we don't want to change these values, so an array of…

Contents