Checking session exists or not- mvc3

孤人 提交于 2019-12-08 04:13:32

问题


I was googling on Sessions and mvc3, and I found this link. To that question a marc-gravell answered

The session only really exists during the processing of an action - I wouldn't expect it to be valid in the constructor of a controller. For example, the controller might (for all I know) be re-used between requests.

I think that may not be the case by reading further on mvc requests and creation of controller, I found this:

A Controller is created for every request by the ControllerFactory (which by default is the DefaultControllerFactory).

So I think, Marc was incorrect and we can simply check the Session exist or not from controller's constructor.

In short, should I follow Marc's answer, or not? Or is there any better way to check sessions with mvc?

来源:https://stackoverflow.com/questions/17362072/checking-session-exists-or-not-mvc3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!