272

I am new to OWIN and Katana. I really don't get why I should use OWIN, while I can use IIS. To simplify, my question is: What do I lose if I skip learning OWIN and use IIS for my websites?

I googled but there is not a simple explanation. There is some information here, but they use some jargon phrases so I cannot understand it.

2

5 Answers 5

279

In asp.net WebApi v2, the OWIN pipeline becomes the default. It is eventually going to be the standard pipeline under any asp.net project.

I cannot put it better than what is written here : http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana

The section "The Open Web Interface for .NET (OWIN)" explains perfectly the goals of OWIN.

Without OWIN, the asp.net bits are coupled to the way IIS communicates with the application. OWIN abstracts web servers and framework components. That means that your application code will now be aware of the OWIN interface, but not of the webserver that is serving the request.

In return, applications can be more easily ported between hosts and potentially entire platforms/operating systems. For example, the ability to host an application in a console or any process allows Mono to host it without efforts... (Raspberry Pi anyone)

The second aspect is that it works as a pipeline.


Owin Pipeline


You can plug any middlewares (and as many as you want) between the webserver and your application.
This allows for more modular solutions. You can develop redistributable middlewares that can impact the request/response coming to/from your application, but keep these modules separated from the application code.

To persuade yourself of the benefits of this modular approach, take a look at the nuget packages available for OWIN : http://www.nuget.org/packages?q=owin

A lot of these packages were previously core asp.net functionality, and have been extracted as middleware.
For example, adding support to login using various OAuth providers becomes an infrastructure concern (a middleware) and does not need to be part of your application code anymore :

Or if you want to automatically replace all the images from your website by cute cat images, you can do that transparently as well :

https://github.com/serbrech/Owin.Catify

EDIT : It is now available as a nuget package : Owin.Catify!

11
  • Your answer surely is good as it upvoted, but its hard for me to figure it out. Jan 23, 2014 at 14:02
  • 5
    How can I make it better? What don't you understand?
    – Stéphane
    Jan 23, 2014 at 14:06
  • 1
    While OWIN does have benfits, it seems difficult to debug as the execution flow will effectively 'jump' from middleware to middleware. Each one potentially changing the response along the way. Visual Studio's attach debugger doesn't seem to be able to follow the flow. And when an exception occours (on a web application), you'll just get a blank page with 200 OK response. No error anywhere apart from the Windows Event log.
    – simbolo
    Jul 14, 2014 at 0:08
  • 7
    I found the explanation at weblogs.asp.net/pglavich/owin-katana-and-getting-started useful. It is a way to decouple your application from IIS and the dependency on System.Web assembly. Reducing the amount of components that are in the HTTP pipeline, thereby keeping the app lightweight.
    – Terence
    Aug 14, 2014 at 14:49
  • 2
    I need to add that in my current environment, some teams use WebApi and some use Nancy. Since both are sitting on top of OWIN, we can share middlewares such as Api Key handling or Stateless Authentication, independently from the framework. We let the team choose what suits them the most. That is the true benefit of OWIN.
    – Stéphane
    Nov 7, 2014 at 10:46
220
public interface OWIN
{
   void ListenHttpCallAndServeWebPage();    
}

namespace Microsoft.OWIN
{
   public class Katana : OWIN
   {
      public void ListenHttpCallAndServeWebPage()
      {
         // listen to a port for HTTP call and serve web page
      } 
   }
}

Yes, thats right. OWIN is an interface and Katana is an implementation of OWIN interface by Microsoft. Therefore we hear these 2 words (OWIN / KATANA) together and manytimes we get confused between the difference between these 2 terms. So, Katana is Microsoft's implementation of OWIN interface. Say there is another company named BIG-BOSS who wanted to create their own implementation of OWIN, they can do that and name their implementation as 'BATANA' and advertise phrases like OWIN / BATANA.

So, why OWIN !!!

Think about a country where the only vehicle available for movement is a truck. Nothing else. If you want to buy a vehicle, you would buy truck. Well, that used to serve good but people started to realize that, they don't need truck all the time, especially when they want to go to watch a movie or buy milk, driving a heavy truck not only costs high fuel, but also add stress on driving. But yes, if they want to carry lots of heavy stuff, truck serves the purpose very well.

Then, the Government of that country came up with a specification for vehicle makers. The specification is as follows:

  1. A vehicle needs to have 4 wheels
  2. A vehicle must have a steering.
  3. A vehicle must have headlight and signal lights.

So, based on these specifications, anyone can make vehicle according to different needs and they can name their vehicle accordingly. Therefore, Sedan, Pickup Truck, SUV, VAN, ..etc.. all kind of vehicle showed up in the market. If someone does not need to carry heavy stuff all the time, rather needs a vehicle just for going to workplace, he/she can buy a little Sedan. Someone can buy SUV if he needs little more power.

Based on the above example, we can say that our ASP.NET Web application uses System.Web Assembly which is heavily loaded (like a truck) and if we want to make a little Web Application where our purpose is just to serve some files based on a little set of requests, we are bound to use that heavy System.Web assembly (truck). Now, OWIN shows up. OWIN is a set of specification (we can call it interface) that defines a Server. Based on that specification, someone (like a vehicle maker) can make various kind of servers based on specific problem domains / application needs. Microsoft created their own Implementation for OWIN named Katana in the same way which can serve Web API. As WebAPI is a light weight technology, which does not need full blown System.Web things, a light weight Server implementation (like Katana) can boost the performance heavily when you use Web Api hosted on Katana.

Now, if you ask, 'Do I need it' ? Answer is, 'It depends on your need of performance'. If you don't mind driving your truck even for going to watch a movie, then, perhaps you do not need OWIN. But if you feel that, a light weight Sedan car is all you need to drive within a city, small distance, watch movie..etc.. yes, You may check what implementations of OWIN available in the market. Katana is one of the implementations of OWIN, therefore you can check what Katana offers. Not only Katana, if any other company implements OWIN according to specific Domain (for example, a server for Medical Devices which will download latest medicine information) and if you are a doctor, perhaps, you can check that implementation of OWIN. Moreover, you yourself can create your own implementation of OWIN targeting any specific niche.

In terms of web applications, if you are a simple Web developer, developing custom Websites for your clients, perhaps, you do not need to worry about custom implementation of OWINs, because IIS will serve you in a balanced way. If you build a Web API project, you will get Katana based template ready made from Visual Studio -> New Project, so you won't have to worry about anything other than learning Katana specific techniques. At this moment, Katana is not mature enough to completely replace the need for IIS for ASP.NET MVC, but perhaps, in the future it will.

Then When I may need to write my own OWIN Implementation ?

Answer: Well, say for example, you have developed a Windows application which should run as a server in the background and listen to a port number XXXX. Your server will respond to only some set of Requests like this:

  1. GET Inventory
  2. DELETE Inventory ID=4
  3. PUT Inventory ID=5

That's all. And nothing else. So, why would you need a full IIS web server for this little task? You can create your own OWIN implementation in that case. (Perhaps, you will use Katana for that)

Ok, so I understood that, if I want to make a ASP.NET MVC website, I don't have the option to replace IIS, then why should I need to know about Katana at this moment ?

Answer: Even though Katana is not mature enough to replace the need of IIS so that you can host your ASP.NET MVC website directly on Katana, but Katana implemented many cool interfaces of OWIN so that you can take the advantage of using those features side by side. For example, allowing your users to login using Facebook, Google, Twitter etc was not very easy before. Katana gives you many hooks (as a middle-ware) so that you can let Katana take care of external Social Media based Authentication easily without writing plumbing code. There are many other benefits to using Katana that you may find out when you start using this technology.

6
  • 2
    I wouldn't say that OWIN is an interface per say, it is a standard, a protocol to standardize the way an application talks to the the host. But is is important to precise that Katana is just an implementation of that standard developed and maintained by microsoft. Other implementations are listed here : github.com/owin/owin/wiki/Implementations
    – Stéphane
    Apr 23, 2014 at 8:24
  • 1
    @Stephane : Well, it may not be just like an interface, I tried to give a high level idea so that someone can understand the relationship between OWIN and KATANA without getting overwhelmed with lots of technical jargons. Apr 25, 2014 at 1:39
  • 1
    "Even though Katana is not mature enough to replace the need of IIS so that you can host your ASP.NET MVC website directly on Katana" seems to indicate that IIS is not important once Katana is 1.0. No, no, that's not correct. Microsoft has Microsoft.Owin.Host.IIS available, which allows web apps + Katana to be hosted directly on IIS (without System.Web of course). IIS is still a key component for ASP.NET applications on Microsoft platform.
    – Lex Li
    May 26, 2014 at 9:05
  • Hi @LexLi, "seems to indicate that IIS is not important once Katana is 1.0" --- No actually I did not mean that. "IIS is still a key component for ASP.NET applications on Microsoft platform." -- Right. Perhaps I oversimplified my explanation so that someone can understand easily and that caused the confusion, but I did not mean otherwise. May 29, 2014 at 17:11
  • 2
    It would be great , if you can help me in understanding - what is lightweight part, i mean if Katana is compared to IIS, by which means it is lightweight ( say it does not do step#1,2,3 etc.. , but IIS does that. Nov 26, 2014 at 19:50
48

A simpler version of that answer is that Katana is gong to fully replace System.Web assembly and the old ASP.NET pipeline, which gives you both better flexibility (use it in more scenarios and use only the parts you like) and performance.

So everyone should watch its evolution now and be ready to switch when it is finally completed.

Below is a diagram I drew to fill in the details Microsoft fails to include in this article.

enter image description here

OWIN is such a standard that it let application frameworks run upon it and forget about everything beneath it. On the other hand, OWIN itself utilizes various host adapters to make sure it can talk to the underlying web servers (IIS and many others).

I am now working with the Jexus web server author to investigate how we can write a host adapter to bridge OWIN/Katana and Jexus. We are really happy to learn that OWIN is flexible and highly customizable.

Reference: https://docs.lextudio.com/blog/why-owin-matters-a-lot-for-asp-net-developers-3377d9d15f02

5
  • So i this answer you say that "Katana is gong to fully replace System.Web assembly and the old ASP.NET pipeline". Does that mean that it can replace all the Server Adapters in your diagram above, or maybe just host.systemweb?
    – netfed
    Mar 9, 2018 at 23:55
  • @netfed unfortunately OWIN itself does and now ASP.NET Core takes over. This question and the answers are all out-of-date.
    – Lex Li
    Mar 9, 2018 at 23:56
  • Aha!! So Asp.net core has Owin capacities? Or Asp.net core works as a collection of modules, where you can implement only those modules you need, and not having to use a larger collection of functions built into System.web?
    – netfed
    Mar 10, 2018 at 0:04
  • 2
    @netfed, OWIN dies (my mobile keyboard changed my words). ASP.NET Core does keep the middleware approach though, and you can assemble its components the way you like, and no more System.Web.
    – Lex Li
    Mar 10, 2018 at 0:13
  • That concludes it all :-) Thank you for clarifying.
    – netfed
    Mar 10, 2018 at 0:20
15

Why I should use OWIN, while I can use IIS?

OWIN is designed to decouple web servers from the frameworks you work under. It can make the applications lightweight and portable for the mixing frameworks and servers.

And Katana is Microsoft’s implementation of OWIN components.

Since last few years Microsoft is making web tools more agile and responsive as the their plan is progressing. For an example, the development of ASP.Net MVC and ASP.Net Web API. They do not depend on System.Web dll which is a huge burden they feel now I think. Advantage is both developments fixes can be provided on a timely manner and the cycle is faster than ever. Also now developers can deploy these applications on custom OWIN hosts or Katana, which is a reference of OWIN implementation.

What's the point after all?

Microsoft has released a project which is a lightweight OWIN based web host on top of IIS, called `Helios. The goal is to avoid ASP.NET/IIS relationship by providing some independent small components that can be used, installed and manage independently running on a web-host that implements the OWIN specifications.

One of the core reasons is the performance-factor. Helios will be able to achieve 2x-3x more throughput than standard ASP.Net application. In terms of memory consumption, Helios is much better than System.Web dll. In a taken benchmark Helios architecture allowed a sample application to achieve 50000 concurrent requests with approximately 1GB less overhead compare to a standard ASP.Net application.

1
0

OWIN is an abstraction between the web application and the hosting platform. If you write your web application using OWIN you are not tied to IIS, you can use another host if you like.

You asked why use OWIN rather than IIS, but these are not alternatives to each other. OWIN sits between IIS and your application so that you can switch out IIS without rewriting your application.

You might also like to check out this page https://github.com/Bikeman868/OwinFramework/wiki/OWIN

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.