Migrate from Katana to ASP.NET Core

Migrate from Katana to ASP.NET CoreIt is possible to migrate from Katana (Microsoft’s OWIN implementation)  to ASP.NET Core.  The secret is in still using the full .NET Framework.

Full Framework?

I recently spoke at the Windsor-Essex .NET Developers group and was explaining to some developers that ASP.NET Core could run on the full .NET Framework.

The reaction I got was slight confusion.  Based on this, I assume there are others that were unaware of this.

The other issue is the term “Full Framework”.  I’m not sure if this is the common term, but I have heard it from many as reference to the .NET Framework that comes shipped with Windows.  This is the framework most are using today.

Why?

The reason you may want to use ASP.NET Core with Full Framework is because you are already using an Owin implementation like Katana.

I’ve previously blogged about how you can use Katana to Self Host ASP.NET Web API as well as NancyFX

ASP.NET Core supports Owin Middleware.  Which means you could migrate your Katana Self Host to use ASP.NET Core with Kestrel.

File > New Project

If you haven’t already, you need to install the .NET Core SDK for Visual Studio.  As of this post, 2016-07-06, Visual Studio 2015 Update 3 has the latest bits.

When you create a new project in Visual Studio, you have the option of created a ASP.NET Core app, but using .NET Full Framework.

ASP.NET Core 1.0 Full Framework

In this example I’m going to create a empty web application.

The next step is to install the Microsoft.AspNetCore.Owin package from Nuget.  This will enable use to Owin Middleware from ASP.NET Core’s IApplicationBuilder.

Install-Package Microsoft.AspNetCore.Owin

Nancy

As you may have already seen on my blog, I’m a fan of Nancy and have been using it with Katana for awhile now.

In order to use Nancy with ASP.NET Core, we can install the same packages we needed when using it with Katana.

Install-Package Nancy

Install-Package Nancy.Owin

Now in our Startup.cs we can add Owin to our pipeline which then can call Nancy.

Docs

The ASP.NET docs have a section related to OWIN that you may find useful.

It is noted in these docs that multiple calls to UseOwin are discouraged for performance reasons and they should be grouped together.

Comments

Let me know if you have migrated your self host Katana or other OWIN Compatible server/application/middleware to ASP.NET Core 1.0


  • Darius D

    Very interesting idea. Would that give any performance improvements?

    • I would assume the actual accepting of the request would be since it’s using kestrel vs httplistener. After it goes through kestrel and gets into your middleware, all would be the same at that point.

  • Chris Harmon

    So I am assuming you just would need to add dependencies for the full framework? Because I’ve been struggling to try using Nancy/Katana/anything to develop some basic proof-of-concept microservices with .NET Core, and keep getting NuGet dependency errors… so maybe this would resolve that issue?? I would hope so.

    I’ve communicated this (NuGet dependency errors with Nancy and .NET Core) to the Nancy team and they said they aren’t yet there for support but I *could* compile the nightly and get it working, which I’ve done, but for trying to use on an upcoming big project I’d rather stick with something not based on nightly builds *just yet*

    • This week I believe that the Nancy team released the Nancy 2.0 beta to NuGet, so you should now be able to use .NET Core instead of full framework. There are some breaking changes related to defining the routes in 2.0 however.

      If you wanted to stick to Nancy 1.x, you would have to continue to use full framework on top of ASP.NET Core and using the OWIN middleware.