I've just known about Session State blocking, so I'm trying to test disabling that kind of blocking with a simple MVC project (the default when creating a new MVC project).
Here is the HomeController
with the only involved About
action method:
[SessionState(System.Web.SessionState.SessionStateBehavior.Disabled)]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
static int c = 0;
static long ci;
[Authorize]
public ActionResult About()
{
var isSecondRequest = ++c == 2;
//Session["a"] = 1;
Debug.Print(">>> Started working ..." + DateTime.Now);
if (isSecondRequest)
{
Debug.Print(">>> current counter: " + ci);
for (long i = 0; i < 10000000000; i++) ;
}
else
{
for (ci = 0; ci < 10000000000; ci++) ;
}
Debug.Print(">>> Finished!");
return Content("welcome");
}
}
I test this by firstly opening two tabs of the home page. Then try clicking on About
link on the first tab and almost immediately switch to the second tab to click on About
one more time. So I expect the line >>> Started working …
should be printed 2 times with timestamps almost the same or having a tiny difference of about 1 or 2 seconds, but the actual difference is up to 21 seconds, like this:
>>> Started working ...4/7/2019 3:16:15 PM
>>> Started working ...4/7/2019 3:16:36 PM
So that means the second request is still blocked, well that's unexpected when I've already applied the attribute SessionStateAttribute
with behavior of Disabled to the HomeController
. And really looks like it does work in another sense that the Session
is null
for each request.
Could you spot anything wrong here? My overall purpose is to disable this kind of blocking so that I can manually manage the concurrent requests and immediately return some helpful message (such as for the second request) to the client so that it's not looking like busy unnecessarily.