开发者

Session variable

Hello I am looking to use a session variable in MVC 3 C# to store a user Id, so that the user doesn't have to enter t开发者_Go百科heir user id on create form

Where should I put the code for the session variable, if not in the global.asax file? i know the code looks something like

    Session["userId"]

I have seen examples using the global.asax but it is very confusing.

Thank you in advance


You can access the Session object in your controllers.

Whether you should is a different question - depending on Session will make your code difficult to test.


If you are planning on using that later on in a few places, a good place to put that in place is in the login part so that you know if a user is logged in the session varaibale is set. You can then access it from any controller if the user is logged in

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜