Home > Backend Development > C#.Net Tutorial > What are the built-in message handlers in Asp.Net webAPI C#?

What are the built-in message handlers in Asp.Net webAPI C#?

王林
Release: 2023-09-11 15:45:06
forward
998 people have browsed it

The message handler is a class that receives HTTP requests and returns HTTP reply. Message handlers are derived from the abstract HttpMessageHandler class. Message handlers provide us with the opportunity to process, edit or reject incoming messages Before the request reaches the HttpControllerDispatcher.

Message handlers are executed earlier in the request processing pipeline, so They are a great place to implement cross-cutting concerns in a Web API. information A handler is nothing more than a series of classes (it may be system-defined or represented by us) sits alongside the process of piping HTTP requests and responses.

Asp.Net webAPI C# 中的内置消息处理程序是什么?

For example, an HTTP request arrives at an HTTP server, now the request will be Passed to HandlerA, after processing in HandlerA, it may go to HandlerB, soon. Now, the advantage here is that we can do this in each The processing procedure depends on our business needs.

In ASP.NET Web API Framework, there are two types of message handlers: usable. They are as follows.

  • Server-side HTTP message handler
  • Client-side HTTP message handler

Server-side message handler

On the server side , the Web API pipeline uses some built-in message handlers -

  • HttpServer strong> to get requests from the host.
  • HttpRoutingDispatcher Dispatches requests based on routing.
  • HttpControllerDispatcher Sends requests to the Web API controller.

We can add custom handlers to the pipeline. Message handlers are great for crosscutting Issues operating at HTTP message level (rather than controller level) action). For example, a message handler might -

  • read or modify request headers.
  • Add response headers to the response.
  • Validate the request before it reaches the controller.

Client-Side HTTP Message Handler

On the client side, the HttpClient class uses a message handler to handle requests. The default handler is HttpClientHandler, which sends the request over the network and get the response from the server. We can insert custom message handlers into the client pipeline.

The above is the detailed content of What are the built-in message handlers in Asp.Net webAPI C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template