开发者

Access the current session variable from another controller

开发者 https://www.devze.com 2023-02-13 22:15 出处:网络
I called a method from another controller using this AnotherController oriCon = new AnotherController();

I called a method from another controller using this

AnotherController oriCon = new AnotherController();
oriCon.ApproveOperation(formCollection, ref responseMsg);

Now, inside the ApproveOperation method, I called the session variable like this

int activeUser = (int)HttpContext.Session["user"];

But its giving me error; null value

I've asked before in forums.asp.net, someone told me to use

HttpContext.Current.Session

But I can't use that, there is no Current property in my HttpContext. Did I have no Current property because I'm using MVC 1.0 framework 3.5. Maybe the guy who answered me using MVC 2.0 framework 4.0?

开发者_StackOverflow

Can anyone give me light on this?


What do you mean "called a method from another controller"?

I don't think you should be doing that. If its a common function that is used by two different controllers then put it in a separate class and then use it. You should be able to access Session from all your controller.

0

精彩评论

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