Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm little-bit confused about session management in MVC4.

Lets say, I entered username and password and clicked on Login button. Then on server side, I got SessionId from HttpContext.Current.Session. And then I am validating that user credentials against database. If user is valid, then Adding SessionId, userName and uiserId in Session.

Lets say, next time request is came from same machine and same browser, I got same SessionId and then allowing that user to access other information.

Now I have following questions:
1. How server come to know that request is came from same browser and from same machine?
2. I found that, SessionId is different for different browser but it is same for same browser on different machine, so If I logged in from machine1 and with google chrome, then is it possible to use same session for different browser?(means session will be available for different machine with same browser. Is it possible?)
3. How server understand that request is for same user, who is logged in?
4. In asp.net session is maintained by viewState, but view state is not used in MVC, then what is used in MVC?
Posted

1 solution

1.In ASP.NET MVC application the Session is working in the same way like in classic ASP.NET web application, and as I know there is no difference between them!

2.For each user that are trying to access the web application by using a web browser ==> a new session will be created and cached for a period of time in that browser for the used computer, so this is the reason because if you are accessing the web application from the same computer by using the same browser two times the same session is used. But if you are trying to access the same web application from two different computers you will got two different Session objects and this do not depends on the used browser.

3.Like I said above the Session for a web client is cached for a timeout period (by using cookies for example), and the session depends on the used browser and computer. All this session timeout and caching parameters are configurable in the web.config.

4.See 1st point above. For details see in MSDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900