asp.net mvc 4 controller execute multiple ajax calls in parallel

耗尽温柔 提交于 2019-12-03 02:52:32

The issue you are facing is caused by the way ASP.NET is managing session. Here is the most important part from ASP.NET Session State Overview (Concurrent Requests and Session State section):

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.

You can resolve your issue if your actions doesn't require access to session. If that is the case, you can decorate the controller with SessionStateAttribute attribute:

[SessionState(SessionStateBehavior.Disabled)]

This way the controller will not have to wait for session.

If your actions require only read access to session, you can try using the SessionStateBehavior.ReadOnly value. This will not result in an exclusive lock but the request will still have to wait for a lock set by a read-write request.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!