ASP.NET MVC 5 concurrent requests are queued even with a session disconnected

Before thinking about going down or telling me "google it", please read this issue carefully. This is an old / classic problem, but the old / classic solution no longer works. Here is a very simple script to play in Visual Studio 2013/2015:

1) Create an ASP.NET web application using the MVC pattern: enter image description here enter image description here

2) Open Controllers \ HomeController.cs and add the attribute to the controller and the "Sleep" action:

[SessionState( System.Web.SessionState.SessionStateBehavior.Disabled)] public class HomeController : Controller { public ActionResult Sleep(int? time) { System.Threading.Thread.Sleep(time ?? 3000); return Content("OK"); } public ActionResult Index() { ... 

3) Open the file: Views \ Home \ Index.cshtml and add / replace the html contents as follows:

 <script> function ReqClick() { var startTime = Date(); $.ajax("/Home/Sleep") .success(function () { var log = $("#log"); var endTime = Date(); log.text(log.text() + "Start: " + startTime.toString() + " === " + endTime.toString()); }); }; </script> <button type="button" onclick="ReqClick();"> Request </button> <div> <textarea id="log" style="width:640px; height:480px"></textarea> </div> 

4) Run it (it doesn't matter if you use IIS or IIS Express or Vs Dev Server) - Open Home / Index. Press F12 to open the developer tool, open the network tab. On the home page, click the "Request" button twice quickly. You can see that the second request takes almost 6 seconds:

enter image description here

enter image description here

In debug mode in the controller, you can see that Session is null:

enter image description here

Cookies are completely empty (no ASP.NET session identifier) enter image description here

Please let me know what I am missing?

Adding the following setting to web.config also does not help:

 <sessionState mode="Off"/> <pages enableSessionState="ReadOnly"/> 
+7
source share
2 answers

I spent a lot of time on this problem and found that most of the information you saw above also did not fix the problem. My concurrent requests were always in the queue, I saw this in Internet Explorer, as well as in Firefox.

I found this article related to using the MVC application of this article.

This shows that you can use Disabled [SessionState(SessionStateBehavior.Disabled)] instead of setting to ReadOnly.

I moved my code that made the AJAX GET call to my own controller, since I had different code in the current controller that used Session via TempData . This fixed my problem, and my call to $.get() for a controller with a disconnected session would handle in parallel with $.post() another controller that was using the session.

+3
source

Parallel parallel queries worked for me when I decorated my controller with this attribute

 [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] 

It works better than the higher disconnected session state and was added back to MVC 3. More details here

+3
source

All Articles