我对MVC4中的会话管理感到有点困惑。
可以说,我输入了用户名和密码,然后点击了Login按钮。然后在服务器端,我从HttpContext.Current.Session获得了SessionId。然后我正在验证针对数据库的用户凭据。如果用户有效,则在Session中添加SessionId,userName和uiserId。
可以说,下次请求来自同一台机器和同一个浏览器时,我得到了相同的SessionId然后允许该用户访问其他信息。
现在我有以下问题:
1.服务器如何知道该请求是来自同一个浏览器和来自同一台机器?
2.我发现,SessionId对于不同的浏览器是不同的,但对于不同机器上的同一浏览器是相同的,所以如果我从machine1和google登录chrome,那么是否可以为不同的浏览器使用相同的会话?(意味着会话可用于具有相同浏览器的不同机器。是否可能?)
3.服务器如何理解该请求是相同的用户,谁登录?
4.在asp.net会话中由viewState维护,但是MVC中没有使用视图状态,那么MVC中使用了什么?
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?
这篇关于Session实际上如何在MVC中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!