Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IIS to recognize OWIN startup class?

Tags:

c#

iis

owin

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?

like image 395
LSpencer777 Avatar asked Nov 18 '13 22:11

LSpencer777


2 Answers

  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.

like image 146
Praburaj Avatar answered Oct 02 '22 19:10

Praburaj


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);

like image 38
Martijn Evens Avatar answered Oct 02 '22 19:10

Martijn Evens