Search code examples
.netasp.net-mvc-5asp.net-web-api2owinkatana

Starting Web Api 2 with OWIN


Currently when I run my ASP.NET Web Api 2 project, it is not using any OWIN middleware. I know this because the "Startup" class (shown below) is not being run:

[assembly: OwinStartup(typeof(MyProject.Startup))]
namespace MyProject
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

Global.asax's Application_Start is still being executed instead.

I have the following OWIN packages installed:

<package id="Owin" version="1.0" targetFramework="net451" />
<package id="Microsoft.Owin" version="3.0.0" targetFramework="net451" />
<package id="Microsoft.Owin.Cors" version="2.1.0" targetFramework="net451" />
<package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net451" />
<package id="Microsoft.Owin.Security" version="3.0.0" targetFramework="net451" />
<package id="Microsoft.Owin.Security.OAuth" version="3.0.0" targetFramework="net451" />

As far as I understand, installing the Microsoft.Owin.Host.SystemWeb package should launch the application in OWIN.

I am using version 5.2.2 of the Web Api framework.


Solution

  • The only difference I can see with my projects is that I have the Microsoft.AspNet.WebApi.Owin package installed:

    Install-Package Microsoft.AspNet.WebApi.Owin -Version 5.2.2
    

    However, there's no need to use the Global.asax file and fire up the Application_Start event. After you have configured the "Startup" class, feel free to delete it.