What's the advantage of using Session-less Controllers in ASP.NET MVC3? [closed]
Asked Answered
D

2

5

Can anyone get me a detailed answer on this?

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

Dourine answered 29/3, 2011 at 6:28 Comment(0)
B
12

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.

Benedictus answered 29/3, 2011 at 6:52 Comment(0)
S
12

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.

Staging answered 29/3, 2011 at 6:48 Comment(1)
+1 aha didn't think about this. Oddly while I was typing my (deleted) answer I mistook Sessions for ViewState =SBuoyancy
B
12

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.

Benedictus answered 29/3, 2011 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.