ASP.NET MVC 5 concurrent requests are queued even with disabled Session

Philipp Munin picture Philipp Munin · Nov 9, 2015 · Viewed 8.1k times · Source

Before thinking about downvoting or telling me "google it", please read the problem more carefully. This is old/classic problem but old/classic solution is no longer working. Here is very simple scenario to reproduce in Visual Studio 2013/2015:

1) Create ASP.NET Web application using MVC template: enter image description here enter image description here

2) Open Controllers\HomeController.cs and add attribute to controller and "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 file: Views\Home\Index.cshtml and add/replace content html with the following :

4) Run it (does not matter if you're using IIS or IIS Express or Vs Dev Server) - Open Home/Index. Click F12 to open dev tool, open network tab. On the Home page click "Request" button twice fast. You can see that second request takes almost 6 seconds:

enter image description here

enter image description here

In Debug mode in controller you can see that Session is null:

enter image description here

Cookies are totally empty (ASP.NET Session Id is absent) enter image description here

Please let me know what I'm missing?

Adding the setting below to web.config does not help either:

<sessionState mode="Off"/>
<pages enableSessionState="ReadOnly"/>

Answer

RayLoveless picture RayLoveless · Jun 6, 2017

Concurrent parallel requests worked for me when I decorated my controller with this attribute

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

It works better than the above disabling session state and was added back in MVC 3. More info here