Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Owin middleware VS WebAPI DelegatingHandler

Tags:

I'm reading around articles and checking exmaples and I see Owin Middlewares are used the same as WebAPI DelegatingHandler: logging incoming requests, validating headers and so on.

My only understanding is that Owin Middleware comes before DelegatingHandlers in the pipeline. So if you create an Owin middleware for let's say Authorization of users, you're able to deny a forbidden request faster, at a lower level.

Is there any difference in the two, or any advantages/disadvantages using either of them?

like image 570
Dan Dinu Avatar asked Aug 01 '16 20:08

Dan Dinu


People also ask

What is the use of OWIN middleware?

OWIN allows web apps to be decoupled from web servers. It defines a standard way for middleware to be used in a pipeline to handle requests and associated responses. ASP.NET Core applications and middleware can interoperate with OWIN-based applications, servers, and middleware.

Is OWIN needed for net core?

NET Core and ASP.NET Core are not based on OWIN. But they support plugging in of OWIN Middleware.

What is ASP.NET Core middleware and how it is different from Httpmodule?

Unlike HttpModules, there is full control of what get's executed and in what order. As they are executed in the order in which they are added. Order of middleware for responses is the reverse from that for requests. Middleware is independent of these events.

What does OWIN stand for?

OWIN (Open Web Interface for . NET) is a standard for an interface between . NET Web applications and Web servers. It is a community-owned open-source project.


1 Answers

I'm also researching this to find out what differences are. I can come up with some idea that may help you. I think about the purpose they are the same, not so much different. But DelegatingHandler is old mechanism compare to owin Owin middlewares:

  1. The purpose of this is separating the server and the application. By doing this, you can inject a lot of modules to your pipeline(that is called owinmiddleware).
  2. By doing this, you can intercept the request at very early stage of httprequest before HttpMessageHandler of web api can process it. For example. you can read the data for initializing dependency before http controller is created.
  3. By doing modules, you can reuse the middleware that asp.net core is focusing.

DelegatingHandler:

  1. It is a part of web api. At this level, we have HttpRequestMessage, HttpResponseMessage, so we can easily manipulate with those rather than owin middleware( for example you can read the data from request message body without worrying we did something that is effecting the message)

  2. By doing that, actually, you are strongly depend on web api pipeline. I'm not saying that you can not reuse it in the furture but it may be happened.

Hope it gives you helpful information about that.

Thanks,

like image 189
tlp Avatar answered Sep 29 '22 07:09

tlp