Middleware in OWIN

There are 2 ways of writing OWIN middleware in ASP.NET Core.

  • Pure OWIN – usefull if you want to integrate with OWIN compatible module but not written in C#
  • ASP.NET Core OWIN middleware

ASP.NET Core Middleware:

This type of middleware can be:

  • delegate of Func<HttpContext, Func<Task>, Task>
  • class with IMiddleware imlementation
app.Use(async (context, next) =>
{
    // Do work that can write to the Response.
    await next.Invoke();
    // Do logging or other work that doesn't write to the Response.
});

Pure OWIN Middleware:

This rather would be used to integrate with OWIN middlewares written in different language, so that ASP.NET Core implementation directly is not possible.

  • delegate of type Func<IDictionary<string, object>, Task>
  • must set keys of owin.ResposeBody and owin.ResponseHeaders

usage in ASP.NET Core pipeline:

public void Configure(IApplicationBuilder app)
{
    app.UseOwin(pipeline =>
    {
        pipeline(next => DelegateTask);
    });
}

Further read:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-6.0

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/owin?view=aspnetcore-6.0

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
21 + 29 =