OWIN中间件被调用的次数比预期的多,我还缺少什么?

Cha*_*ari 5 iis owin katana

我正在测试OWIN中间件,并编写了以下中间件类。但是奇怪的是,当我请求没有任何路径(localhost:<port>)的URL时,我总共调用此中间件大约四次。但是,当我打电话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());
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的启动配置:

    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();
    }
Run Code Online (Sandbox Code Playgroud)