Introduction
In this series of articles, we’ll learn all about OWIN features included in ASP.NET 4 and above. We will learn what OWIN is, how it works with ASP.NET, and what features it provides.
From the past few years, web application development has been extremely evolved and it's moving from monolithic frameworks towards more modular, loosely coupled individual working components that can be used and swapped easily without affecting the rest of the application. Basically, the architecture says, to use only what you need and this gives us benefits like better performance and flexibility.
ASP.NET web stack including ASP.NET (MVC, WebForms, Web Pages, Web APIs, SignalR) is dependent on System.Web assembly. In fact, every feature of ASP.NET is written in System.Web and System.Web assembly is part of the .NET framework. This is where problems start occurring because we can’t add new functionality without a new framework release. As .NET is huge and it has other components as well besides ASP.NET, so frequent release of a new framework is not possible. This means we can’t frequently add new features to ASP.NET in this modern evolutionary era of web technologies. Another problem with ASP.NET is its hard reliance on IIS. IIS is Microsoft's Internet Information Services which provides hosting services for .NET web apps at production.

Due to rapid changes in web technologies, the ASP.NET team is also changing the framework toward modern web development architecture which contains individually working pluggable components that can be used and swapped with each other independently from the host. This is where OWIN plays its role and provides solutions to the problems that we have with existing architecture. Now, let’s see how it fits into the picture.
What is OWIN?
OWIN is an acronym for Open Web Interface .NET. The name doesn’t really explain what OWIN is yet it gives us some hint that it’s something related to the Web and it is Open and for . NET. The www.owin.org website gives the following definition of OWIN,

The goal of OWIN is to decouple a web application from a web server so that we don’t have to worry about how the application will be deployed; instead, we just focus on solutions to our problems. OWIN provides an abstraction layer between a web server and a web application. Now, the question is how someone abstracts a web server from a web application.
Abstracting away a web server from a web application is, for sure, a very complex job and it should be understandable to the average developer. But OWIN has made it very simple and it abstracts a web server with a standard .NET delegate called AppFunc that takes System.Collections.Generic.IDictionary<string, object> as an argument and returns a System.Threading.Tasks.Task.

Every OWIN middleware takes an AppFunc as a parameter to communicate with each other and with the Server as well. The dictionary object is called the environment dictionary and it contains all information about HTTP requests that the server has passed to the application and the returning task object tells the server when the application has done processing.
Remember, OWIN is just a specification, it’s not a framework that you can download and install or get from NuGet Package Manager. It’s just a specification and it can have many implementations. Katana is one such implementation of OWIN that Microsoft has written for .NET web developers and introduced into the ASP.NET 4 framework release. The new ASP.NET Core is way ahead in that direction.
Parts of the OWIN Application
Now that we know about what Owin is and about the functionality it provides, let’s look into different parts one by one that are involved in the execution of the OWIN app from starting the app to receiving incoming HTTP requests and returning HTTP responses.
Host
Host is someone that hosts everything else, and starts an application along with the other parts of it. For an OWIN, the host can be any running Windows process from a console app to Windows service and even IIS.

Server
The server is responsible for listening to incoming HTTP requests and returning responses to clients. In the case of IIS, both, the server and the host are IIS.

Pipeline
The server passes the request into the application through a pipeline of OWIN middleware using AppFunc. OWIN middleware is a self-contained piece of code that can inspect and modify both, incoming requests and outgoing responses. When a middleware receives a request using AppFunc, it performs some processing and when it completes the work, it passes the dictionary object to the next middleware. The idea is very similar to HTTP modules but instead, OWIN middleware is not event-driven and it's independent of IIS.

Application
Application is part of the system that is responsible for generating the actual response for an application that will be sent back to the client. Technically, there is no difference between an OWIN middleware and an application despite the application being intended to generate a response.

So, these are the parts that are involved in building an OWIN-based application.
Application Flow
Let’s take a step-by-step tour of an OWIN-based application from incoming requests to outgoing responses.
Step 1. At first, a client of some kind creates a connection to the server and sends an HTTP request.











Nitin JainPosted Jul 4, 2019, 2:07 PM
Nice one...simple but precise article...waiting for next one. Thanks
Prasad korhalePosted Jun 14, 2019, 1:37 PM
Very informative and precise article Mobeen. Thank you!
Ehsan SajjadPosted Jun 13, 2017, 2:27 PM
Very well wrote, will be waiting for other parts :)
Manikandan MurugesanPosted Jun 13, 2017, 1:14 PM
Lot of information abt ASP.NET....That's cool...waiting for nxt part..Keep sharing..