Iis OWIN中间件被调用的次数比预期的要多,我遗漏了什么?
我正在测试OWIN中间件,并编写了以下中间件类。但奇怪的是,当我请求一个没有任何路径的URL(Iis OWIN中间件被调用的次数比预期的要多,我遗漏了什么?,iis,owin,katana,Iis,Owin,Katana,我正在测试OWIN中间件,并编写了以下中间件类。但奇怪的是,当我请求一个没有任何路径的URL(localhost:)时,我发现这个中间件总共被调用了四次。但是,当我调用localhost:/welcome.htm或调用localhost:/default.htm时,只会按预期调用一次。我错过了什么 public class MyMiddleware : OwinMiddleware { public MyMiddleware(OwinMiddleware next) :
localhost:
)时,我发现这个中间件总共被调用了四次。但是,当我调用localhost:/welcome.htm
或调用localhost:/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();
}
public void配置(IAppBuilder-appBuilder)
{
appBuilder.UseErrorPage(新的ErrorPage选项{
ShowCookies=true,
ShowEnvironment=true,
ShowExceptionDetails=true,
ShowHeaders=true,
ShowQuery=true,
ShowSourceCode=true,
SourceCodeLineCount=2
});
appBuilder.Use();
appBuilder.UseWelcomePage(“/welcome.htm”);
appBuilder.UseStaticFiles();
}
您可以通过fiddler检查HTTP请求并将相关请求发布到此处吗?注意:不鼓励调用Next和写入响应正文。如果有人设置了内容长度,您可能会违反它。这些请求是否来自浏览器?浏览器可以对/favicon.ico等资源发出附加请求