I am new to MVC3 and coming from a Winforms background. I have a two-part question. The first is simple - if I have a Controller with a private non-static variable in it, will I have a separate "instance" of that variable for each user that browses to my application?
The second is more of a general question... but I'm not sure of the right words to ask it. =) Let's suppose that my web app sits on a server that is being fed some text via the network, and needs to post that text to a particular end user (via AJAX), how do I "find" that user's session? I'm worried about the goal being to post the text in only one user's browser when there might be 50 connected to the server. What's the right way to go about that?
Thanks!
if I have a Controller with a private non-static variable in it, will I have a separate "instance" of that variable for each user that browses to my application
Yes, you will have a separate instance for each user request. You will have a separate instance of the controller (and the private field) even for the same user if he performs consecutive requests. A controller's lifetime is tied only to a given HTTP request.
how do I "find" that user's session?
ASP.NET tracks user sessions using cookies. Cookies are automatically sent along AJAX requests so the server will be able to identify the user. Take a look at ASP.NET Session state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With