Skip to content
txgz999 edited this page Jul 27, 2019 · 10 revisions

OWIN and Katana

OWIN:The Open Web Interface for .NET Katana: a flexible set of components for building and hosting OWIN-based web applications on .NET Framework

https://github.com/aspnet/AspNetKatana/

https://github.com/aspnet/AspNetKatana/wiki/Packages

Katana is the Microsoft’s implementation of OWIN. It consists of a list of Nuget packages. Most of their names have prefix Microsoft.Owin. Some of the packages I have used are

  • Microsoft.Owin.Security.Cookies - Middleware that enables an application to use cookie based authentication, similar to ASP.NET's forms authentication.
  • Microsoft.Owin.Security.OAuth - Middleware that enables an application to support any standard OAuth 2.0 authentication workflow.
  • Microsoft.Owin.Host.SystemWeb - OWIN server that enables OWIN-based applications to run on IIS using the ASP.NET request pipeline.

When we want to use OWIN in ASP.NET applications, Microsoft.Owin.Host.SystemWeb is a must to install. Then we all add a Startup class, which is the place we add OWIN middle wares to run in the application. Other packages are installed and often introduced there to meet our needs.

Project Katana: Whereas both the OWIN specification and Owin.dll are community owned and community run open source efforts, the Katana project represents the set of OWIN components that, while still open source, are built and released by Microsoft. These components include both infrastructure components, such as hosts and servers, as well as functional components, such as authentication components and bindings to frameworks such as SignalR and ASP.NET Web API.

Some history can be found in https://forums.asp.net/t/2112718.aspx?Owin+Katana+with+MVC.

Steps to use Katana

  • In VS2017, create a new ASP.NET Web Application (.NET Framework) project with .NET Framework 4.6.1, choose the Empty project template.
  • Install Nuget package Microsoft.Owin.Host.SystemWeb
  • Create a StartUp.cs file with the following content:
public class Startup {
   public void Configuration(IAppBuilder app) {
      app.Run(context => {
         context.Response.ContentType = "text/plain";
         return context.Response.WriteAsync("Hello World!");
      });
   }
}
  • run the application, we should be able to see "Hello World" in the browser.

Steps to Use Nancy

  • In VS2017, create a new ASP.NET Web Application (.NET Framework) project with .NET Framework 4.6.1, choose the Empty project template.
  • Install Nuget package Microsoft.Owin.Host.SystemWeb
  • Install Nuget package Nancy.Owin
  • Create a StartUp.cs file with the following content (similar to asp.net core application, the Configuration method below constructs OWIN pipeline):
public class Startup {
    public void Configuration(IAppBuilder app) {
        app.UseNancy();
    }
}
  • add a Nancy module (similar to MVC controller) HomeModule.cs:
public class HomeModule: NancyModule {
    public HomeModule() {
        Get("/", parameters => {
            var model = new { title = "Hello World" };
            return View["home", model];
        });
    }
}
  • add a Nancy view Home.html:
<!DOCTYPE html>
<html>
<head>
    <title></title>
	<meta charset="utf-8" />
</head>
<body>
    @Model.title
</body>
</html>
  • run the application, we should be able to see "Hello World" in the browser.

Resources

Clone this wiki locally