简体   繁体   中英

Why my session is getting lost on calling a base

I'm loosing my session when I call the base method, is there a reason to get null session?

here is my controller action

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

There's something strange going on with your code. It should work just fine.

Some things to help you to debug:

  • Make sure you are not trying to access Session["storedevices"] on the BaseController before the Controller.Session property is actually populated. For instance, it's supposed to be null on the Controller's constructor. It's only available after the Initialize method, if I can remember well.
  • Make sure this.Session == base.Session . For some reason, you might be "newing" the Session property in the descendant Controller. Just put a breakpoint there and make sure this expression is true.
  • Make sure this.Session == System.Web.HttpContext.Current.Session both in the descendant Controller and in the base Controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM