OWIN中间件被调用的次数超过预期,我错过了什么?

时间:2014-07-26 03:17:31

标签: iis owin katana

我正在测试OWIN中间件并编写了以下中间件类。但奇怪的是,当我请求没有任何路径的URL(localhost:<port>)时,我发现这个中间件总共被调用了四次。但是,当我致电localhost:<port>/welcome.htm或致电localhost:<port>/default.htm时,它只会按预期调用一次。我错过了什么?

public class MyMiddleware : OwinMiddleware
{
    public MyMiddleware(OwinMiddleware next)
        : base(next)
    {
    }

    public override async Task Invoke(IOwinContext context)
    {
        await this.Next.Invoke(context);

        if (context.Request.Path.HasValue && (context.Request.Path.Value == "/" || context.Request.Path.Value.EndsWith(".htm")))
        {
            using (var writer = new StreamWriter(context.Response.Body))
            {
                await writer.WriteLineAsync("Next middleware: " + this.Next.ToString());
            }
        }
    }
}

这是我的启动配置:

    public void Configuration(IAppBuilder appBuilder)
    {
        appBuilder.UseErrorPage(new ErrorPageOptions {
            ShowCookies = true,
            ShowEnvironment = true,
            ShowExceptionDetails = true,
            ShowHeaders = true,
            ShowQuery = true,
            ShowSourceCode = true,
            SourceCodeLineCount = 2
        });

        appBuilder.Use<MyMiddleware>();

        appBuilder.UseWelcomePage("/welcome.htm");
        appBuilder.UseStaticFiles();
    }

0 个答案:

没有答案