Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
878 views
in Technique[技术] by (71.8m points)

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

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 ControllersHomeController.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: ViewsHomeIndex.cshtml and add/replace content html with the following :

<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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...