Run Asp.Net Mvc as OWIN middleware?
Asked Answered
T

4

24

Is it possible to run Asp.Net Mvc as OWIN middleware? What is necessary for this? I can't seem to find anything about this but I have no idea why it wouldn't be possible.

Is it possible? Is it easy? Does the question make sense?

Tattan answered 6/3, 2014 at 23:31 Comment(5)
Why do you want to do that? What's the use case?Giefer
@GeorgeStocker at the moment just knowledge, but eventually to be able to distribute vertical application slices via nuget as OWIN middleware. For example a user management component that includes the ui for administering user accounts could be built in asp.net mvc and included in an Mvc, Webforms, Nancy, and OpenRasta project equally.Tattan
Another use case is to create a standalone console app that is capable of executing any in-browser unit tests (eg jasmine)Tattan
@GeorgeStocker Here's the use case: have middleware-based authentication that works for MVC, WebAPI, SignalR. Turns out that currently MVC resets Thread.CurrentPrincipal to the value produced by HttpApplication.AuthenticateRequest, unless you add an AuthenticationFilter. Maybe I'm doing something wrong, but seems like MVC is effectively ignoring some effects if OWIN middlewares. And it's not great, kind of breaks the whole idea of middlewares.Ely
@PavelGatilov that might just be the result of the fact that asp.net is not fully integrated with the concept of middleware yet. Until the next version of asp.net comes out it's in a "hacked into place" stateTattan
M
25

Currently ASP.NET MVC doesn't run on OWIN. Web API will because it's been decoupled from System.Web, specifically HttpContext. This is the main dependency that prevents MVC from running on OWIN as well.

Some alternatives that do run on OWIN are FubuMVC, Nancy and Simple.Web

Menstruation answered 9/3, 2014 at 5:5 Comment(2)
How come that you can use owin features in an mvc project (blogs.msdn.com/b/webdev/archive/2013/07/03/…) but can't run mvc on owin? How does using owin from mvc but not running mvc on owin work at all? Is there an article or something I can read to clarify that?Scrivings
@zespri that's what the owin.host.systemweb package is all about. There are articles but the idea is this - it's supposed to be that mvc, web api, etc are all implemented as OWIN middleware. That's not quite possible at the moment (soon). So instead this package implements OWIN in the same way as Mvc - as an HttpModule (a crappier IIS version of the same concept). This ends up giving most of, but not all of the benefits of standard OWIN.Tattan
D
10

No, MVC depends on System.Web.dll (and thus IIS).

Darya answered 7/3, 2014 at 21:57 Comment(3)
I don't understand. Why does a dependency on IIS mean that I can't run it as OWIN middleware? Can't you build OWIN middleware that adapts an IHttpHandler or am I missing something?Tattan
In theory it's possible, but it's not that way today. You can combine the two -- OWIN middleware can run in the IIS pipeline, but MVC itself is not a pure OWIN middleware component (and as such can't run in a non-IIS OWIN host, for example).Darya
Is this still valid in 2020?Typhon
E
5

Checkout project Helios. Possibly fill the need.

Excurvate answered 7/3, 2014 at 22:53 Comment(0)
K
4

You may look at Katana.Boot.AspNet but as Chris Ross said it's just a "hello world" prototype without any futher development. Also you may look at OWIN Gate's era ASP.NET pipeline adapter.

Kowtko answered 8/3, 2014 at 22:4 Comment(1)
Oh! And here we can change the world :^)Kowtko

© 2022 - 2024 — McMap. All rights reserved.