Session and Streams

The final answer to this question could not be found when the client session was established in the ASP.NET MVC2 application. I assume that a specific thread from the thread pool is processing this request. Does the same thread always handle all subsequent requests for this session? So, theoretically, if somehow the session identifier was corrupted and the wrong stream was selected, will any session level data be missing? Thanks

+6
multithreading session
source share
2 answers

In short, no, not under IIS (I can't vouch for the Cassini web development server in Visual Studio, but I doubt it too)

You can demonstrate the flow change by adding the following to the view:

<%= System.Threading.Thread.CurrentThread.ManagedThreadId %> 

Now hit the page several times from your browser (or perhaps hit it from 2 or 3 browsers), and you will see that it changes from time to time.

Having said that, in a simple scenario, for example, you can often see the same thread serving the request, since ASP.NET does not create more threads than necessary, but as soon as you start loading the server, you will see several threads.

+3
source share

Not. Each request can be processed by a different thread. This means that different resources on a page can be handled by different threads. Or they can be processed on the same. It depends on the workflow and iis to figure out whether to create a new thread or better wait until it becomes available.

The page will be displayed in a single stream, and then images, style sheets and javascripts can be processed on the same or different stream. This is fundamental to ASP.NET graduate students and web programming in general. This allows you to balance all your requests on different servers or even in different domains.

This brings us to your question about the state of the session. You must not lose session IDs between requests. If so, then something serious is wrong. Or you may be in a web farm / cluster situation where one request is sent to one server and the next to another through some load balancing.

In load balancing mode, you should have some ways to maintain session state. The two most common approaches are to maintain a database and distributed cache. Later, my preferred approach, because session data is inherently temporary and does not belong to constant db.

+2
source share

All Articles