What is the process that makes IIS start responding to requests through the Owin pipeline?

有些话、适合烂在心里 提交于 2019-12-04 06:16:07

Starting with ASP.NET 4, you can now define a custom class in your code (referenced DLL or source code), with a particular convention and have it invoked by the ASP.NET system way early in the pipeline.

Just need to mark it with the PreApplicationStartMethodAttribute

The Microsoft.Owin.Host.SystemWeb assembly makes use of this feature and if we reflect on the code, we can see that this startup 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 then on, the OwinHttpModule takes over and goes into the OwinBuilder and OwinAppContext flows, which looks up the Startup class in your assembly to invoke the Configuration method.

Microsoft.Owin.Host.SystemWeb subscribes to the PreApplicationStart event. When this event fires we register an HttpModule which contains all the logic to detect Startup class and build the OWIN pipeline etc.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!