Introducing Helios Based OWIN Application

Introduction

I previously described the ASP.NET Project "Helios". Now in continuation of that article I am developing a sample application here with which you can learn to apply the Helios host on the OWIN application.

Prerequisites

Though I've described all minimum system requirements so that I am using the following:

  • Visual Studio 2013
  • Windows 8

Note: You need to make sure that you are using the latest updated version of the NuGet Package for the Visual Studio 2013 or you can update it from the NuGet Gallery.

Getting Started

So, let's start to develop the application with the following sections:

  • Creating OWIN application
  • Adding Helios to an existing OWIN application

Creating OWIN Application

In this section, we'll create the OWIN application on the Helios Host using the ASP.NET Web Application. Let's start with the following procedure.

Step 1: Open Visual Studio 2013 and click on "New Project".

Creating New Project in VS 2013

Step 2: Select the ASP.NET Web Application and enter the name.

Creating ASP.NET Web Application

Step 3: Select the Empty Project Template from the "One ASP.NET" wizard.

Creting Empty Project in VS 2013

Step 4: In the Solution Explorer, right-click on the "References" and click on "Manage NuGet Packages" and install the Microsoft.Owin.Host.IIS as in below:

Owin Host in NuGet Package

Step 5: Now install this in your application.

Installiing Owin Host in Web Application

Step 6: Add a OWIN Startup class to your project.

Adding OWIN Startup Class in Application

Step 7: Replace the code with the following code:

using Microsoft.Owin;

using Owin;

 

[assemblyOwinStartup(typeof(HeliosWebApp.OwinStartup))]

 

namespace HeliosWebApp

{

    public class OwinStartup

    {

        public void Configuration(IAppBuilder OwinApp)

        {

            OwinApp.Run(async appContext =>

            {

                appContext.Response.ContentType = "text/plain";

                await appContext.Response.WriteAsync("Hello & Welcome To C-SharpCorner");

            });

        }

    }

}

Step 8: Press Ctrl+F5 or F5 to run the application and you will the see the browser as in below:

Owin Startup Class Execution

Now in the preceding application you can see that the newly created OWIN application is running atop the Helios Host for IIS. If you want to check whether or not the assembly named System.Web is involved, change the application code to the following code:

using Microsoft.Owin;

using Owin;

using System;

 

[assemblyOwinStartup(typeof(HeliosWebApp.OwinStartup))]

 

namespace HeliosWebApp

{

    public class OwinStartup

    {

        public void Configuration(IAppBuilder OwinApp)

        {

            OwinApp.Run(async appContext =>

            {

                appContext.Response.ContentType = "text/plain";

                await appContext.Response.WriteAsync("List of All Assemblies defined here:" + Environment.NewLine);

 

                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())

                {

                    await appContext.Response.WriteAsync(assembly.FullName + Environment.NewLine);

                }

                await appContext.Response.WriteAsync(Environment.NewLine);

                await appContext.Response.WriteAsync("Stack Traces are:"Environment.NewLine);

                await appContext.Response.WriteAsync(Environment.StackTrace);

            });

        }

    }

}

Now run the application.

Getting Assemblies List in Application

Now you can see that the System.Web.dll or related assemblies are not present in the stack trace at all. They are not present even in the current AppDomain.

Adding Helios to an Existing OWIN Application

We can also add Helios to an existing OWIN application. I am using here my existing SignalR OWIN based application.

Step 1: Open the existing application in the Visual Studio 2013.

Step 2: Now click on "References" to open the "Manage NuGet Packages".

Manage NuGet Package

Step 3: Now install the Microsoft.Owin.Host.IIS in the application

Step 4: Now remove the Microsoft.Owin.Host.SystemWeb. It is optional to remove.

Removing OwinHost Reference

Step 5: Now you can run the application.

That's it. The only thing is needed that we can convert a web-hosted OWIN application to a Helios-hosted OWIN application. There are not other changes should be necessary, as long as the application is based on OWIN.

Summary

This article described the use of a Helios based OWIN application and you can also learn to apply it to the existing OWIN application. Thanks for reading.