14

I've declared the following in my application:

[assembly: OwinStartup("MyClass", typeof(MyClass), "ConfigureOwin")]

Defined a startup class:

public class MyClass {

    public void ConfigureOwin(IAppBuilder appBuilder) {

    }

}

And start owin like this:

WebApp.Start<MyClass>("baseUri");

However, it's not working. WebApp always tries to look for a method named 'Configuration' even if I define to look for something else. What could I do?

Acrotygma
  • 2,531
  • 3
  • 27
  • 54
  • Possible duplicate of [OwinStartup not Starting ... Why?](http://stackoverflow.com/questions/19760545/owinstartup-not-starting-why) – John Sep 08 '16 at 08:40
  • This is dublicate. See this answer: https://stackoverflow.com/a/20204884/3558141 – hakanaltindis Mar 31 '20 at 10:12

6 Answers6

42

For me, I needed to add Microsoft.Owin.Host.SystemWeb as a reference. (Click Manage Nuget Packages and search for it.)

Thanks to this blog post for the tip.

I ran into this issue because I migrated from Web API to Web API with OWIN middleware for ADFS authentication.

Jess
  • 23,901
  • 21
  • 124
  • 145
  • I was trying to add the packages to get a vanilla MVC app to use the OAuth middleware. Got most of the OWIN installed, however, without Microsoft.Owin.Host.SystemWeb, the Startup.cs wasn't running, just takin up space. – Jester Oct 13 '15 at 04:38
  • I _always_ forget that one :-( – Thomas Eyde Nov 24 '15 at 12:22
25

If you're using optimizeCompilations="true" in your web.config you may need to set it to false and back to true.

joshschreuder
  • 1,413
  • 2
  • 18
  • 32
7

Both OwinStartupAttribute and WebApp.Start<T>(StartOptions) are ways to specify what class to use to configure the OWIN pipeline, both will assume that the specified type has a method with the signature Configuration(IAppBuilder).

However, the OwinStartupAttribute has overloads to specify an optional method name. AFAIK there's no overload to specify method name when using the WebApp.Start<T> method.

The OwinStartupAttribute is most useful when you have an external component that "kickstarts" the OWIN pipeline, e.g. an ASP.NET handler (using Microsoft.Owin.Host.SystemWeb) or Helios (using Microsoft.Owin.Host.IIS). If you're self-hosting (using Microsoft.Owin.Host.HttpListener), it's best to use the WebApp.Start methods.

Here's a great resource on OWIN Startup Class Detection.

khellang
  • 17,550
  • 6
  • 64
  • 84
  • Ah, however it seems that automatic startup doesn't really work in self hosted processes. Removing WebApp.Start just with OwinStartupAttribute and app.config does absolutely nothing. – Acrotygma Mar 14 '14 at 13:04
  • You're correct. There's nothing to "kickstart" the application when self-hosting (in a web scenario it would be an ASP.NET handler or Helios (pure IIS)). If you're self-hosting, I'd go with the `WebApp.Start` approach and just stick to the conventions :) – khellang Mar 14 '14 at 13:05
  • +1 for pointing out that `OwinStartupAttribute` needs to be kick started by the ASP.Net handler when hosted in IIS – Darbio Aug 15 '14 at 01:30
2

In your web.config appSettings, try adding this:

<appSettings>
    <add key="owin:AutomaticAppStartup" value="true" />
</appSettings>
codeMonkey
  • 4,134
  • 2
  • 31
  • 50
0

They are various reasons for startup.cs not trigger, One common issue is the startup.cs runs successfully, but the debugger does not fire up, Assuming you have all components installed, then it could be the web project url is assigned to work with an external host, change that to IIS Express will detect it...

go to Web Project settings, Web, then in the servers section choose IIS express.

0

I have the same problem, I added Microsoft.Owin.Host.SystemWeb as a reference, later add startup class, but in my case, I need to change the order of the reference in the .csproj file, put it in the first positions, and It works for me.

source