Message handlers and the http module?

In the ASP.NET Web API, HTTP requests and responses are processed in a pipeline on the server.

If I want to add logical or global behavior in the very early stages of the pipeline, I have to do this in a message handler. (e.g. authentication)

But what about the Http module pipeline? where does it fit into the whole story?

Looking at these numbered phases of the web api life cycle:

http://i.stack.imgur.com/jkQe8.jpg

enter image description here

But looking at the general events of the Http module (contains more, but ...) enter image description here

Question:

- How do these 2 systems come together and where? I mean, if there was 1 image that contains web api and http module, how would the numbers be? (I added numbers to the images for easy reference)

- I always hear that if I want to do something earlier on the pipeline, I should use message handlers, but what about the HttpModule BeginRequest for example? I know that at this stage there are objects that are null, but still, the later stages in httpmodule inflate HttpContetxt objects - and yet, the guys from webapi say: use MessageHandlers .... (this is due to the fact of the self-propelled environment )?

+5
source share
1 answer

To combine the figure lower to upper, imagine that the IHttpHandler field in the upper figure corresponds to the ASPX in the image below, so that you place the lower image in the lower left upper. So, 8 and 9 are part of the ASP.NET IIS pipeline. IIS pipeline runs modules, etc. And it ends when the handler processes the request. With the web API, this handler turns out to be the HttpControllerHandler , and here the web API pipeline begins. If you look at the HttpControllerHandler , the request and response will be ASP.NET specific left and right, it will become the HttpRequestMesssage , which is specific to the Web API.

To your second question, the earliest of which you can do in the Web API pipeline will be a message handler. HttpModule will be even earlier, but is not part of the Web API, but is a hosting. The trade-off is that if you have an HttpModule, you can only use it in IIS, whereas a message handler can work on any host, as it is specific to the web API and specific to the host. I keep referring to my MSDN article in my recent SO answers, but then it happens that the article is relevant to the questions asked. So, I have no choice but to tie it again. Here you go . I compare the various options in this article.

+5
source

Source: https://habr.com/ru/post/1205467/


All Articles