C# 为什么我的会话在呼叫基地时迷失了方向
当我调用基方法时,我正在丢失会话,是否有理由获取空会话 这是我的控制器动作C# 为什么我的会话在呼叫基地时迷失了方向,c#,asp.net-mvc,asp.net-mvc-4,session,C#,Asp.net Mvc,Asp.net Mvc 4,Session,当我调用基方法时,我正在丢失会话,是否有理由获取空会话 这是我的控制器动作 public class SystemAdminController : BaseController { [HttpPost] public ActionResult Index(string removeItems) { //Session["storedevices"] <<<< my session data is still avai
public class SystemAdminController : BaseController
{
[HttpPost]
public ActionResult Index(string removeItems)
{
//Session["storedevices"] <<<< my session data is still avail
RemoveItemFromGrid(removeItems); //<<< as soon as I call this method my Session get lost why?
}
}
public class BaseController : Controller
{
public void RemoveItemFromGrid(string items)
{
//Session["storedevices"] //Session is null/lost here?
//to do
}
}
你的代码有点奇怪。它应该很好用 帮助您调试的一些内容: 确保在实际填充Controller.Session属性之前,您没有尝试访问BaseController上的会话[storedevices]。例如,在控制器的构造函数中,它应该为null。如果我记得清楚的话,它只有在初始化方法之后才可用。 确保this.Session==base.Session。出于某种原因,您可能正在子代控制器中更新会话属性。只需在那里放置一个断点,并确保此表达式为true。 确保子控制器和基本控制器中的this.Session==System.Web.HttpContext.Current.Session。
我正在访问BaseController上的会话[storedevices],因为我已经在RemoveItemFromGrid上面发布了代码。那么我应该在BaseController初始化中做什么呢?只需尝试使用HttpContext.Current.Session[key]包装每个会话,然后重试