2015-04-07 50 views
0

我在调用基础方法时失去了会话,是否有理由获得空会话?为什么我的会话在拨打基地时迷路了

这里是我的控制器操作

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 
    } 
} 
+0

刚刚尝试用'HttpContext.Current.Session [键]来包装你的每一个会议',并尝试 –

回答

0

有你的代码会在一些奇怪的事情。它应该工作得很好。

有些事情来帮助你调试:

  • 确保你是不是想在BaseController访问Session["storedevices"]实际上是填充Controller.Session属性之前。例如,它应该在Controller的构造函数中为null。只有在Initialize方法之后才有效,如果我能记得的话。
  • 请确保this.Session == base.Session。出于某种原因,您可能正在“新增”后代控制器中的Session属性。只要在那里放置一个断点,并确保这个表达式是真实的。
  • 确保this.Session == System.Web.HttpContext.Current.Session都在后代控制器和基本控制器中。
+0

我访问的''BaseController'会话[“storedevices”]'因为我已经发布上​​面的代码'RemoveItemFromGrid'so我应该在'BaseController'初始化中做些什么? –

相关问题