Question

Can anyone get me a detailed answer on this?

What's the advantage of using Session-less Controllers in ASP.NET MVC?

Was it helpful?

Solution

If you have a Session-less Controller then you will be able service simultaneous requests from the same browser instance. Otherwise, ASP.NET will queue up the requests as they are received in order to give them sequential access to the ASP.NET Session object, to avoid deadlock issues or other race conditions.

You can actually have 1 request to a 'Session-ful' Controller and multiple requests to 'Session-less' Controllers simultaneously. This pattern has been useful to me in implementing a long-running process (implemented through a 'Session-ful' AsyncController) with AJAX calls from the client to a 'Session-less' Controller which provides the user with updates as to how far through the long-running process the server is.

OTHER TIPS

In one word: Scalability. If you don't use session at all it means that your application is stateless which is great. In a web farm scenario you just throw another server and you are ready to tackle a new load of your site. You could also use out of process sessions (like SQLServer or StateServer) and the session will be shared between all nodes of the farm but then this state server becomes a sensible single point of failure of the entire site.

There is also another issue with sessions: because session is not thread safe if there are two parallel requests for the same session (think AJAX calls) to a controller action which writes to the session those two requests will simply queue and execute sequentially.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top