This project has moved. For the latest updates, please go here.

Using Katana middleware in IIS with Application Routing

Oct 28, 2013 at 8:21 AM
Is it possible to use Katana middleware components (for authentication etc.) in conjunction with ARR on IIS? In my scenario, I need the middleware component to perform an authentication routine before the routing module (ARR) routes the request to another server. Does it depend on the ordering of the modules? Is it possible to make sure the OWIN pipeline is invoked before ARR kicks in?

Thanks,
Priya
Coordinator
Oct 28, 2013 at 3:46 PM
Interesting. You can make OWIN middleware run at different stages in the pipeline by setting app.UseStageMarker(...). See this write-up:
http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline

I can't find a concrete answer for when ARR kicks in, but you can experiment with the available stages and see what works.

You may also need to enable RAMFAR: <modules runAllManagedModulesForAllRequests=“true” />
Oct 28, 2013 at 5:49 PM
Thank you for your post. I used exactly that post(that you linked to) to get an example up and running. Works very well... But with ARR in the picture, my initial attempt didn't work so well. Might well be a case of incorrect configuration . I have a redirect rule setup to a different host, and the redirect seems to happen before Katana is hit. Way I see it, in IIS integrated mode, Katana is acting like any other httpmodule, so there's no reason my request shouldn't be able to flow through it before it hits the ARR module.

Will post details once I get it working :)
Oct 29, 2013 at 7:41 AM
Finally managed to make this work. I had to do the following to make this happen:

1) My app was configured as an application under the default web site. Setting ARR rules at the app level didn't work but setting them at the default site level worked perfectly.


2) In my initial tests, I had integrated with Nancy and my startup class contained the code
app.UseNancy();
I had to comment that out to make the rewrite work.


So...finally, I registered my middle ware component for the "authenticate" stage and was able to verify that this code is hit before ARR reroutes the request to the final configured destination.
Nov 7, 2013 at 8:22 AM
An update on this....the Katana middleware component is triggered as long as the ARR rule is configured on the site level. However, if the ARR rule is configured at the server level, the middleware component is not triggered at all..I'm guessing this is because the processing happens before the site's app code is triggered.
Nov 11, 2013 at 8:15 AM
Final update...managed to get this to work. The reason my middleware component was not being triggered when ARR rule was configured at the global (server) level was because of a missing config setting (mentioned by Tratcher earlier in this thread):

<modules runAllManagedModulesForAllRequests=“true” />

Adding this setting to the config file did the trick.

Lessons learnt:

1) Use the above setting always

2) Use the correct stage marker
Marked as answer by pmarwa on 11/11/2013 at 10:27 PM