是什么使IIS开始通过管道Owin响应请求的过程? [英] What is the process that makes IIS start responding to requests through the Owin pipeline?

查看:727
本文介绍了是什么使IIS开始通过管道Owin响应请求的过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您创建在Visual Studio中一个空的ASP.NET Web应用程序项目2013打开包管理器控制台和安装包Microsoft.Owin.Host.SystemWeb

If you create an empty ASP.NET Web Application project in Visual Studio 2013 open the package manager console and install-package Microsoft.Owin.Host.SystemWeb

添加一个启动类与配置(IAppBuilder应用程序)的方法,例如:

Add a Startup class with a Configuration(IAppBuilder app) method, for example:

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

和运行,你会看到你好在浏览器中显示出来。但是,你看项目,有任何文件没有变化,即web.config中,这表示正在使用的管道Owin。更重要的是,如果你有启动类,但不安装Microsoft.Owin.Host.SystemWeb包启动的配置方法永远不会运行。

And run, you'll see hello show up in the browser. However, it you look at the project, there's no change to any files, namely to web.config, that indicates that the Owin pipeline is being used. More importantly, if you have the Startup class but don't install the Microsoft.Owin.Host.SystemWeb package the Startup's Configuration method won't ever be run.

我怀疑有一个自定义模块和处理器介入使得这一切发生,但无法找到关于它的任何文件。这倒是略微这个问题,我能找到的是<一个唯一href=\"http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline\">this.

I suspect there's a custom module and handler involved in making all this happen but can't find any documentation about it. The only thing that marginally touches this subject that I was able to find was this.

它是如何,你可以通过引用某些DLL更改请求的处理方式?

How is it that you can change the way a request is handled just by referencing some dlls?

推荐答案

在ASP.NET 4开始,你现在可以在你的code自定义一个类(参考DLL或源$ C ​​$ C),用特别约定,并经ASP.NET的系统管道的方式调用初

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.

只是需要将其标记的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.$p$papplicationstartmethodattribute.aspx\">$p$pApplicationStartMethodAttribute

该Microsoft.Owin.Host.SystemWeb装配使得利用这一特性,如果我们反思code,我们可以看到,这种启动方法注册Owin模块:

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

从此,在 OwinHttpModule 接管并进入 OwinBuilder OwinAppContext 流动,它看起来了启动类在汇编调用配置方法。

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.

这篇关于是什么使IIS开始通过管道Owin响应请求的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆