ASP.NET MVC and Ajax, concurrent requests?

后端 未结 6 1503
花落未央
花落未央 2020-11-27 04:15

AJAX newbie here!
At the moment in my ASP.NET MVC web app my AJAX requests appear to be getting batched or queued, im not sure.
No requests seem to be getting comp

相关标签:
6条回答
  • 2020-11-27 04:40

    ASP.NET will serially process requests on a per-session basis unless sessions are configured as disabled or read only in web.config via the enableSessionState attribute on the pages element.

    As this is a page setting, this will not affect MVC controllers and they will still be subject to serial request processing.

    Curiously, even with sessions disabled or set to readonly, we can still read and write session data. It seems to only affect the session locking that causes serial request processing.

    <system.web>
        <pages enableSessionState="ReadOnly"/>
    </system.web>
    

    Pages can also have an enableSessionState property, though this is not relevant to MVC views.

    <%@ Page EnableSessionState="True" %>
    
    0 讨论(0)
  • 2020-11-27 04:50

    Since .NET Framework v3.0 released, you can use "SessionStateBehavior" enum with SessionStateAttribute:

    [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class MyController : BaseController { }
    
    0 讨论(0)
  • 2020-11-27 04:50

    I suggest using jQuery for your ajax needs with asp.net mvc, I have used it exclusively and it has been extremely easy.

    As for tutorials I would look at this: http://docs.jquery.com/Ajax

    There are tons of options to play with and I also suggest downloading firebug so you can watch requests launch from your page asynchronously and see if they fire and what they return etc.

    Like the other guy side, AJAX request are asynchronous and don't get queued up and they all return independently when they finish, so if you watch in firebug it will be easy to see what is going on behind the scenes and before the debugger gets hit

    0 讨论(0)
  • 2020-11-27 04:53

    I'm expanding on Lachlan Roche's answer, which is correct.

    The ASP.NET framework will "single-thread" requests that deal with Session scope (a global resource), to prevent one request from interfering with another. In WebForms I think you can use the Page directive to specify that individual pages don't use Session and therefore don't need to treated synchronously like this.

    The problem is that in ASP.NET MVC all requests use Session, because it's used to implement TempData. You can disable session state entirely, as Lachlan Roche pointed out, or you can deal with this on a case-by-case basis.

    A possible solution might be to kick off your own background threads to process any long-running code, so that the initial request "completes" as quickly as possible.

    0 讨论(0)
  • 2020-11-27 04:53

    Well Concurrent Request are more on browser dependent aswell if you fire suppose 10 concurrent request to an action Using AJax in Mozilla and same using IE 8 then you will find that Mozilla has style to fire one request wait for its response and then fire second and so on... for this is one by one basis whereas in IE * this fire about 6 concurrent request at a time to Server.

    So Concurrent Request are also dependent on browser type.

    0 讨论(0)
  • 2020-11-27 04:54

    With the release of ASP.MVC 3 you can now add an attribute to your controllers to mark the Session as readonly, which allows actions to be called concurrently from the same client.

    Sessionless Controller Support:

    Sessionless Controller is another great new feature in ASP.NET MVC 3. With Sessionless Controller you can easily control your session behavior for controllers. For example, you can make your HomeController's Session as Disabled or ReadOnly, allowing concurrent request execution for single user. For details see Concurrent Requests In ASP.NET MVC and HowTo: Sessionless Controller in MVC3 – what & and why?.

    - from this DZone article.

    By adding SessionState(SessionStateBehaviour.Disabled) to your controller, the runtime will allow you to invoke multiple actions concurrently from the same browser session.

    Unfortunately I don't think there is a way to mark an action so as to only disable the session when that action is called, so if you have a controller that has some actions that require the session and others that do not, you will need to move the ones that do not into a separate controller.

    In later versions of ASP MVC you can decorate individual controller classes with the SessionStateAttribute

    [System.Web.Mvc.SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class MyController : Controller 
    {
    }
    
    0 讨论(0)
提交回复
热议问题