What is the process that causes IIS to respond through the Owin pipeline?

If you are creating an empty ASP.NET web application project in Visual Studio 2013, open the package manager console and the Microsoft.Owin.Host.SystemWeb installation package

Add a launch class using the Configuration application (IAppBuilder), for example:

public class Startup { public void Configuration(IAppBuilder app) { app.Run(context => context.Response.WriteAsync("hello")); } } 

And run, you will see hello in the browser. However, you look at the project, there are no changes in any files, namely web.config, which indicates that the Owin protocol is used. More importantly, if you have the Startup class, but don’t install the Microsoft.Owin.Host.SystemWeb package, then the start method will not start.

I suspect that the user module and handler are involved in this, but cannot find documentation about it. The only thing that slightly concerns this topic that I could find is this .

How can you change the way a request is processed only by referencing some DLLs?

+7
c # iis owin katana
source share
2 answers

Starting with ASP.NET 4, you can now define a custom class in your code (a link to a DLL or source code), with a specific convention, and call it using the ASP.NET system method at the beginning of the pipeline.

Just tick it PreApplicationStartMethodAttribute

The Microsoft.Owin.Host.SystemWeb assembly uses this function, and if we think about the code, we will see that this launch method registers the Owin module:

 public static class PreApplicationStart { private const string TraceName = "Microsoft.Owin.Host.SystemWeb.PreApplicationStart"; /// <summary> /// Registers the OWIN request processing module. /// </summary> public static void Initialize() { try { if (OwinBuilder.IsAutomaticAppStartupEnabled) { HttpApplication.RegisterModule(typeof(OwinHttpModule)); } } catch (Exception exception1) { Exception exception = exception1; ITrace trace = TraceFactory.Create("Microsoft.Owin.Host.SystemWeb.PreApplicationStart"); trace.WriteError(Resources.Trace_RegisterModuleException, exception); throw; } } } 

From now on, OwinHttpModule takes over and goes into the OwinBuilder and OwinAppContext streams , which look for the Startup class in your assembly to call the Configuration method.

+8
source share

Microsoft.Owin.Host.SystemWeb subscribes to the PreApplicationStart event. When this event fires, we register an HttpModule that contains all the logic to determine the launch class and build the OWIN pipeline, etc.

See OWIN Middleware in the integrated IIS pipeline. Although OWIN middleware (OMC) components are primarily designed to run on the server-agnostic pipeline, it is also possible to run OMC in the integrated IIS pipeline (classic mode is not supported). An OMC can be created to work in the IIS integrated pipeline by installing the following package from the Package Manager Console (PMC): Install-Package Microsoft.Owin.Host.SystemWeb

+5
source share

All Articles