IIS Web请求上的Owin无限期挂起 [英] Owin on IIS web requests hang indefinitely
问题描述
我们正在Win 2012 R2的IIS 8.5上的负载平衡器后面运行Owin应用程序.一种情况是,对某些URL的请求会无限期地挂起.如果用户在浏览器中选择取消",然后重新加载页面,则一切正常,服务器响应迅速.
We are running an Owin applications on IIS 8.5 on Win 2012 R2 behind a loadbalancer. One some occations, requests to certain URLs hang indefinitely. If the user selects cancel in the browser, and reloads the page, everything is OK and the server responds quickly.
在IIS管理器中,我们可以看到请求挂起: 挂起似乎发生在Owin管道内部.我们正在运行.NET 4.5.2和最新的Owin软件包.
In IIS manager, we can see the requests hanging: The hang seems to occur inside the Owin pipeline. We are running .NET 4.5.2 and the latest Owin packages.
这是/api/whoami
端点的代码:
[Authorize]
public class WhoAmIController : ApiController
{
[Route("whoami")]
[HttpGet]
public IHttpActionResult Whoami()
{
return Json(ClaimsPrincipal.Current.Identity.Name);
}
}
一个观察结果是,对此端点的请求挂在IIS管道的AuthenticateRequest
阶段,而不是PreExecuteRequestHandler
,这是OWIN管道的默认IIS阶段.我们唯一的身份验证方法是cookie身份验证,它在AuthenticateRequest
阶段执行.
An observation is that requests to this endpoint hangs in the AuthenticateRequest
stage in the IIS pipeline, not PreExecuteRequestHandler
which is the default IIS stage for the OWIN pipeline. Our only authentication method is cookie authentication, which executes in the AuthenticateRequest
stage.
有什么想法吗?
调整后的屏幕截图
推荐答案
问题是我们有代码在IIS事件PreSendRequestHeaders
上执行,根据
The problem was that we had code executing on the IIS event PreSendRequestHeaders
, which apperently is bad according to
http://www.asp.net/aspnet/overview/web-development-best-practices/what-not-to-do-in-aspnet,-and-what-to-do-instead#presend
我们的目的是在所有请求的输出途中调整HTTP标头.解决方法是将代码移至BeginRequest
事件.
Our intention was to adjust HTTP headers on the way out on all request. The fix was to move the code to the BeginRequest
event.
这篇关于IIS Web请求上的Owin无限期挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!