36

My OWIN web service runs beautifully in Visual Studio 2013, but when I publish it to a real IIS site, it acts as if the Configuration method in the startup class has not been run. I can do "normal" things like browse to the app and see the directory structure, but nothing that was supposedly set up with the IAppBuilder is functional. For example, I get a 404.0 error when I browse to a URL that was set up in Startup to issue an OAuth2 bearer token. It's as if Startup.Configuration(IAppBuilder app) was never run.

I'm using the [assembly: OwinStartup(typeof(MyNamespacedStartupClass))] attribute to designate the startup class.

I've used NuGet to get both Microsoft.Owin.Host.SystemWeb and Microsoft.Owin.Diagnostics per instructions I've seen, but that doesn't make a difference.

What more do I have to do?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
LSpencer777
  • 1,769
  • 2
  • 13
  • 14
  • 1
    1) Make sure your app pool is in v4.0 integrated mode. 2) Make sure you have bin placed Microsoft.Owin.Host.SystemWeb (I see you have installed it) - Just make sure its also in the bin folder. You can check if this article is helpful : http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline – Praburaj Nov 19 '13 at 15:55
  • Your #1 was the answer! If you'll post it as an answer rather than a comment, I can give you credit. :) – LSpencer777 Nov 19 '13 at 18:56

5 Answers5

29
  1. Make sure your app pool is in v4.0 integrated mode.
  2. Make sure you have bin placed Microsoft.Owin.Host.SystemWeb (I see you have installed it) - Just make sure its also in the bin folder.

This article will have more information on how an OWIN middleware runs on Integrated pipeline.

Praburaj
  • 11,417
  • 1
  • 23
  • 20
  • 3
    You should add at least a minimun code sample of the linked document. If the external links dissappears, this answer will become useless. – JotaBe May 07 '15 at 09:25
  • 2
    Adding Microsoft.Owin.Host.SystemWeb solved my problem. I created an empty WebApi app and had to add OWIN references manually. – Alex Klaus Aug 17 '15 at 02:49
13

I also had to add an extra setting to my web.config

<configuration>    
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />       
    </system.webServer> 
</configuration>

From: https://katanaproject.codeplex.com/wikipage?title=Static%20Files%20on%20IIS

IIS has a native static file module that is optimize to skip other portions of the pipeline if it sees file paths that do not match other handlers (e.g. not aspx). This means that the directory browser middleware is likely to work, but then the static file middleware may be bypassed in favor of the native static file module.

This tells IIS not to skip the managed Asp.Net modules even if the native static file module thinks it has a match.

It also describes another step, but this was not needed for me:

Also, add the following stage marker AFTER your static file middleware (in namespace Microsoft.Owin.Extensions): app.UseStageMarker(PipelineStage.MapHandler);

Community
  • 1
  • 1
Martijn Evens
  • 266
  • 3
  • 5
5

Probably the reason if you upgraded at some point from an older MVC:

Make sure you don't have

  <add key="owin:AutomaticAppStartup" value="false" />

in your web.config. It will suppress calling the startup

Instead change it to this

  <add key="owin:AutomaticAppStartup" value="true" />

Somewhere along the line - when I upgraded to MVC 5 this got added (actually almost ironically it was a year ago tomorrow) and I never even knew what owin was until today when I tried to use it.

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
5

I also faced same problems when I migrated my already running MVC5 site to a new server. It gave me nightmares, just to recap I had to do all this to get it working

  1. Add [assembly: OwinStartupAttribute(typeof([YourAssemblyName].Startup))] this to the Startup class (after the using statements and before the namespace declaration)
  2. Add these keys to the <appSettings> section of web.config

    <add key="owin:AppStartup" value="[NamespaceForYourStartUpClass].Startup, [YourAssemblyName]" />
    <add key="owin:AutomaticAppStartup" value="true" />
    
  3. And lastly as suggested by Martijn Evens add the following to <system.webserver> section in web.config

    <modules runAllManagedModulesForAllRequests="true" />
    
tomRedox
  • 28,092
  • 24
  • 117
  • 154
Niraj
  • 1,782
  • 1
  • 22
  • 32
0

For those who deal with legacy and (or) have migrated versions. Check windows "Roles and features", find what version of ASP.net is installed, and use exactly the same version in web.config for targetFramework, for example in my case it was 4.6 not 4.8, so

<system.web>
    <httpRuntime targetFramework="4.6" requestValidationMode="2.0" maxQueryStringLength="2097151" />
    <compilation targetFramework="4.6" optimizeCompilations="true">
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103