Introduction
This article introduces the configuration of the OWIN Startup Class. I provided an overview of OWIN and Katana in my previous article. In an OWIN application there is a Startup class that determines the components for the pipeline of the application. I am defining the OWIN startup class.
In that context, you can connect with your OWIN startup class at runtime by various ways. It depends on your hosting model like IIS, OwinHost, IIS-Express. The following are ways to connect the Startup class with the hosting runtime:
ASP.NET Application with OWIN
Let's start to create an ASP.NET Web Application in which we use the OWIN Startup using following the procedure.
Step 1: Create a new project.
Step 2: Create an application with an empty project template.
Step 3: Open the NuGet Package Manager.
Step 4: Install the OwinHost.
Step 5: Add a OWIN Startup Class.
Step 6: Replace the code with the following code:
using System;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(OwinDemo.Startup))]
namespace OwinDemo
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
string time=DateTime.Now.Millisecond.ToString();
app.Run(async context =>
{
await context.Response.WriteAsync(time + " " + "Welcome to OWIN Application");
});
}
}
}
Step 7: Debug your application.
OWIN Startup Class
As I said earlier, you can add multiple OWIN Startup classes. So add multiple classes like Brand and Model.
Step 1: Add another OWIN Startup class with the name BrandStartup.cs.
Step 2: Change the code in the OwinDemo namespace with the following code:
namespace OwinDemo
{
public class BrandStartup
{
public void Configuration(IAppBuilder app)
{
string time = DateTime.Now.Millisecond.ToString();
app.Run(context =>
{
return context.Response.WriteAsync(time + " " + "Welcome to Brand OWIN Application");
});
}
}
}
Step 3: Debug the application.
Step 4: Add another OWIN Startup class with the name ModelStartup.cs.
Step 5: Change the code in the OwinDemo namespace with the following code:
namespace OwinDemo
{
public class ModelStartup
{
public void Configuration(IAppBuilder app)
{
string time = DateTime.Now.Millisecond.ToString();
app.Run(context =>
{
return context.Response.WriteAsync(time + " " + "Welcome to Model OWIN Application");
});
}
}
}
Step 6: Debug the application.
Note: As you can see, the application is by default running the Startup class. If you want to run another startup class then it is as follows.
Step 1: Open the Web.Config file and write the following code in it:
<configuration>
<appSettings>
<add key="owin:appStartup" value="Brand"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
</configuration>
Step 2: Change the assembly code as follows:
[assembly: OwinStartup("Brand", typeof(OwinDemo.BrandStartup))]
Note: I am changing it in the BrandStartup.cs file code.
Step 3: Debug your application.
Summary
So this article will help you to configure the OWIN Startup class and multiple Startup classes. This is done in the latest Visual Studio 2013 RC release. So just use this feature with the RC 2013. Thanks for reading.