为什么会产生多个同时AJAX调用同一个ASP.NET MVC的行动会导致浏览器以阻止? [英] Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?

查看:148
本文介绍了为什么会产生多个同时AJAX调用同一个ASP.NET MVC的行动会导致浏览器以阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天后,我问这个问题:

A few days back I asked this question:

为什么$ .getJSON()块浏览器?

我火在同一个控制器的动作pretty的6 jQuery的异步Ajax请求多的一次。每个请求都需要10秒才能返回。

I fire six jQuery async ajax requests at the same controller action pretty much all at once. Each request takes 10 seconds to return.

通过调试和记录请求的操作方法,我注意到,请求进行串行化,绝不并行运行。比如我看到一个时间轴在我log4net的日志是这样的:

Through debugging and logging requests to the action method I notice that the requests are serialised and never run in parallel. i.e. I see a timeline in my log4net logs like this:


2010-12-13 13:25:06,633 [11164] INFO   - Got:1156
2010-12-13 13:25:16,634 [11164] INFO   - Returning:1156
2010-12-13 13:25:16,770 [7124] INFO   - Got:1426
2010-12-13 13:25:26,772 [7124] INFO   - Returning:1426
2010-12-13 13:25:26,925 [11164] INFO   - Got:1912
2010-12-13 13:25:36,926 [11164] INFO   - Returning:1912
2010-12-13 13:25:37,096 [9812] INFO   - Got:1913
2010-12-13 13:25:47,098 [9812] INFO   - Returning:1913
2010-12-13 13:25:47,283 [7124] INFO   - Got:2002
2010-12-13 13:25:57,285 [7124] INFO   - Returning:2002
2010-12-13 13:25:57,424 [11164] INFO   - Got:1308
2010-12-13 13:26:07,425 [11164] INFO   - Returning:1308

看着在Firefox网络时间表我看到这样的:

Looking at the network timeline in FireFox I see this:

两种以上的日志的示例和火狐网络的时间表是一组相同的请求。

Both the log sample above and the Firefox network timeline are for the same set of requests.

被序列化的请求同样的动作在同一页面?的我所知道的串行访问会话对象在同一会话,但没有会话数据被感动。

Are requests to the same action from the same page serialised? I'm aware of serialised access to the Session object in the same session, but no session data is being touched.

我剥夺了客户端code到一个单一的请求(运行时间最长的一个),但是这仍然阻挡浏览器,也就是当AJAX请求完成并在浏览器响应任何链接点击。只有

I stripped the client side code down to a single request (the longest running one) but this still blocks the browser, i.e. only when the ajax request completes does the browser respond to any link clicking.

我也看到这里(在Chrome的开发者工具)是在点击时,长时间运行的ajax请求执行它链接报告了无法加载资源错误随即这表明浏览器已经杀害了(或正在尝试杀死并等待?)Ajax请求:

What I also observe here (in Chrome's developer tools) is that upon clicking on a link when a long running ajax request is executing it reports a Failed to load resource error immediately which suggests that the browser has killed (or is attempting to kill and waiting?) the ajax request:

但是浏览器仍需要年龄将重定向到新的页面。

However the browser still takes an age to redirect to the new page.

是Ajax请求真正异步或者这是戏法,因为JavaScript实际上是单线程?

Are ajax requests really asynchronous or is this sleight of hand because javascript is actually single threaded?

是我的请求,只是时间太长,这个工作?

Are my requests just taking too long for this to work?

该问题发生在Firefox和IE浏览器也是如此。

The problem occurs in Firefox and IE as well.

我也改变脚本中使用 $ AJAX 直接和明确地设置异步:。真正的

I also changed the script to use $.ajax directly and explicitly set async: true.

我在IIS7.5运行此,同时在Windows 2008 R2和Windows 7的味道做同样的事情。

I'm running this on IIS7.5, both the Windows 2008R2 and Windows 7 flavours do the same thing.

调试和发布版本也具有相同的行为。

Debug and release builds also behave the same.

推荐答案

答案在盯着我的脸。

ASP.NET会话状态概述

访问ASP.NET会话状态是专属每个会话,这意味着,如果两个不同的用户作出并发请求,获得每个单独会话并发理所当然的。然而,如果两个并发请求在同一会议上提出的(使用相同的SessionID值),第一个请求获取独占访问会话信息。第二个请求的第一个请求完成后才能执行。

Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished.

烦人我倒是脱脂段这几个星期前,没有真正采取了大胆的句子的富有冲击力。我读过这只是作为的访问会话状态是序列化的而不是的所有请求,无论你是否触摸会话状态或不被序列化的,如果要求来自同一个会话。

Annoyingly I'd skimmed paragraph this a couple of weeks ago not really taking in the full impact of the bold sentences. I had read that simply as "access to session state is serialised" and not "all requests, no matter whether you touch session state or not, are serialised" if the requests came from the same session.

幸运的是有一个变通的ASP.NET MVC3及其可能创建会话少控制器。斯科特·格思里谈论这些位置:

Fortunately there is a work around in ASP.NET MVC3 and its possible to create session-less controllers. Scott Guthrie talks about these here:

<一个href="http://weblogs.asp.net/scottgu/archive/2010/12/10/announcing-asp-net-mvc-3-release-candidate-2.aspx">Announcing ASP.NET MVC 3(候选发布版2)

我安装MVC3 RC2和升级项目。装饰有问题的控制器 [SessionState会(SessionStateBehavior.Disabled)] 解决了这个问题。

I installed MVC3 RC2 and upgraded the project. Decorating the controller in question with [SessionState(SessionStateBehavior.Disabled)] solves the problem.

当然,通常我只是几分钟前发现了这个在堆栈溢出:

And of course typically I just found this in Stack Overflow a few minutes ago:

<一个href="http://stackoverflow.com/questions/2927726/asynchronous-controller-is-blocking-requests-in-asp-net-mvc-through-jquery">Asynchronous控制器通过jQuery的堵在ASP.NET MVC请求

Asynchronous Controller is blocking requests in ASP.NET MVC through jQuery

这篇关于为什么会产生多个同时AJAX调用同一个ASP.NET MVC的行动会导致浏览器以阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆