에 두 번 호출 : 내 Startup.Configuration에 쿠키 인증 미들웨어를 추가OWIN AuthenticationMiddleware는 owin 쿠키 인증 미들웨어를 사용하는 동안 나는 문제가 요청
, 내 미들웨어의 모든 요청에 두 번 호출됩니다, 이것은 내입니다 코드 : 다음
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
// this code will be executed twice per http request
return next();
});
// my cookie middleware
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
AuthenticationMode = AuthenticationMode.Active
});
}
와 나는 구현 빈과 AuthenticationMiddleware에서 상속 자신 미들웨어를 writed, 그냥 같은 일이야 - 내 미들웨어의 모든 요청에 두 번 호출합니다.
public override async Task Invoke(IOwinContext context)
{
AuthenticationHandler<TOptions> handler = CreateHandler();
await handler.Initialize(Options, context);
if (!await handler.InvokeAsync())
{
await Next.Invoke(context);
}
await handler.TeardownAsync();
}
내가 await Next.Invoke(context);
다시 호출 내 미들웨어의 모든 원인이됩니다 발견 :
하지만 다른 미들웨어 (StaticFiles 미들웨어, Webapi 미들웨어)를 사용하면 모든 것이 잘됩니다.
OWIN 또는 AuthenticationMiddleware에 대해 뭔가를 놓쳤습니까?
요청 당 내 미들웨어가 두 번 호출되는 이유는 무엇입니까? 그것은 설계에 의한 것인가?
예, 마지막 오우 인 미들웨어에서 요청을 처리해야합니다. 미들웨어가 요청을 처리하지 않으면 (그리고 마지막 미들웨어가 next();를 반환합니다), 모든 미들웨어가 다시 호출됩니다. – acmajia