Problem with ASP. NET MVC Session Lock

Source: Internet
Author: User

has been using the session, the session lock does not have much attention, may be usually not noticed. Some time ago suddenly found that an AJAX GET request, direct access to the address, only dozens of MS, but loaded in the page, but requires 2s. Finally, the problem of locating the session.

Specific content I saw someone else's article in the garden: http://blog.csdn.net/paolei/article/details/38052129

However, some problems have also been identified.

For example, this example:

Back end:

    public class Mycontroller:controller    {        //get:my public        actionresult Index ()        {            return View ();        }        [HttpGet] public        string GetTest1 ()        {                        thread.sleep (+);            return "GetTest1";        }        [HttpGet]        public string GetTest2 ()        {            return ' GetTest2 ';        }    }

Front:

    function (resp) {        //  server response    });    $.get (function  (resp) {        //  server response    });

Direct use of the above code, no access to the session, the code by default does not perform session lock, running results:

GetTest2
GetTest1

After writing the session in the controller:

         Public actionresult Index ()        {            session["a", "a";             return View ();        }

Operation Result:

GetTest1
GetTest2

Then press above before controller add: [SessionState (System.Web.SessionState.SessionStateBehavior.ReadOnly)], run again, found the result is the same, The description readonly is invalid.

In fact, although it is readonly, but the code is still written, this and ReadOnly is obviously contradictory, but the code will not error, but this property is invalid.

Later, changed to: [SessionState (System.Web.SessionState.SessionStateBehavior.Disabled)]

At this time to run again, the direct error.

Finally summed up, as long as the controller in the session of the write, no matter what the controller before the Sessionstatebehavior, will think the session is writable, session lock will be performed. Therefore, if the Ajax concurrency performance requirements are relatively high, you can not use the session. So, think sessionstatebehavior this attribute a little chicken ah. My humble opinion, if have a master hope pointing twos.

Later, I think of their own application is not a way to put another Ajax load slower, using timeout 20ms, this is called a complex computation to load to-do number, and the other is to load the page list data, it is obvious that users initially want to see the list of data first.

Problem with ASP. NET MVC Session Lock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.