Asp.net mvc 3 无法在ASP MVC3中使用会话

Asp.net mvc 3 无法在ASP MVC3中使用会话,asp.net-mvc-3,session,Asp.net Mvc 3,Session,我从一个登录页开始,在那里我从一个控制器调用一个函数,为一些会话赋值。但我似乎无法使用它们,因为我得到的对象引用未设置为对象的实例。以下函数正文第一行的异常: public void assignNewUserToSession(string currentButtonID, string user, string app) { Session["buttonID"] = currentButtonID; Session["user

我从一个登录页开始,在那里我从一个控制器调用一个函数,为一些会话赋值。但我似乎无法使用它们,因为我得到的
对象引用未设置为对象的实例。
以下函数正文第一行的异常:

public void assignNewUserToSession(string currentButtonID, string user, string app)
        {
            Session["buttonID"] = currentButtonID;
            Session["userID"] = user;
            Session["appID"] = app;
        }
public void landingPage()
        {
            FC.assignNewUserToSession("34", "asd", "gsds");

            Media(); // This is the view Controller for another page.
        }
此异常通常在使用尚未初始化的变量时引发,即=为null或nothing。但据我所知,会话不必以任何其他方式初始化,我在上面的代码中已经这样做了

这里是我调用上面函数的地方:

public void assignNewUserToSession(string currentButtonID, string user, string app)
        {
            Session["buttonID"] = currentButtonID;
            Session["userID"] = user;
            Session["appID"] = app;
        }
public void landingPage()
        {
            FC.assignNewUserToSession("34", "asd", "gsds");

            Media(); // This is the view Controller for another page.
        }
有什么问题吗?

试试看

HttpContext.Current.Session 
而不是

Session 
希望这对你有帮助

谢谢你试试这个

   HttpContext.Current.Session["buttonID"]=currentButtonID;
   HttpContext.Current.Session["userID"] = user;
   HttpContext.Current.Session["appID"] = app;

哪里调用了
landingPage
?@RGraham-我将其设置为在解决方案运行时调用。As
Start URL
@AmitAgrawal-另一个控制器的对象引用,其中函数
assignNewUserToSession()
为.yes,有效。但我不能就这样使用它。我必须使用完整的库参考
System.Web.HttpContext….
,否则它将找不到“Current”作为属性。但是我找不到使用System.Web.HttpContext将库作为
包含。你知道为什么吗?在命名空间中包括System.Web我有。我不是那个笨蛋D