- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are built-in message handlers in Asp.Net webAPI C#?
A message handler is a class that receives an HTTP request and returns an HTTP response. Message handlers derive from the abstract HttpMessageHandler class. Message handlers provide us the opportunity to process, edit, or decline an incoming request before it reaches the HttpControllerDispatcher.
Message handlers are executed much earlier in the request processing pipeline, hence they are a great place to implement cross cutting concerns in Web API. Message Handlers are nothing but a chain of classes (it may be system defined or defined by us) that sits next to the process of HTTP request and response through a pipeline.
For example, one HTTP request has come to a HTTP server, now the request will be passed to HandlerA and after processing it in HandlerA, it might go to HandlerB and so on. Now, the advantage here is that we can perform specific tasks within each handler depending on our business needs.
In ASP.NET Web API Framework, there are two types of message handlers are available. They are as follows.
- Server-Side HTTP Message Handlers
- Client-Side HTTP Message Handlers
Server-Side Message Handlers
On the server side, the Web API pipeline uses some built-in message handlers −
- HttpServer gets the request from the host.
- HttpRoutingDispatcher dispatches the request based on the route.
- HttpControllerDispatcher sends the request to a Web API controller.
We can add custom handlers to the pipeline. Message handlers are good for crosscutting concerns that operate at the level of HTTP messages (rather than controller actions). For example, a message handler might −
- Read or modify request headers.
- Add a response header to responses.
- Validate requests before they reach the controller.
Client-Side HTTP Message Handlers
On the client side, the HttpClient class uses a message handler to process requests. The default handler is HttpClientHandler, which sends the request over the network and gets the response from the server. We can insert custom message handlers into the client pipeline.
- Related Articles
- How to add custom message handlers to the pipeline in Asp.Net webAPI C#?
- What is ViewData in ASP .Net MVC C#?
- What is the significance of NonActionAttribute in ASP .Net MVC C#?
- What are the levels at which filters can be applied in ASP .Net MVC C#?
- What is the use of ChildActionOnly attribute in ASP .Net MVC C#?
- How to use ViewBag in ASP .Net MVC C#?
- What are the three segments of the default route, that is present in ASP .Net MVC\nC#?
- What are built-in class attributes in Python?
- How can we provide an alias name for an action method in Asp .Net MVC C#?
- What are access specifiers in C#.NET?
- What are the in-built functional interfaces in Java?
- What are the different types of filters in C# ASP.NET WebAPI?
- What are the common built-in data types in Python?
- What are the different access specifiers in C#.NET?