Session object is null in ASP.NET MVC Controller

This is a strange problem because yesterday I was executing my code in Cassini (VS2008) and in the controller action method the Session object was valid and contained the session data. Today I restarted VS2008 and opened the project and the Session object is null.

What are the reasons why a Session object might be empty in controller code in an ASP.NET MVC application?

0


a source to share


1 answer


I found the problem.



I have used LINQ to retrieve the IEnumerable from the business layer and then iterate over it in the view. The problem was that LINQ was lazy loading and didn't try to load the contents of the list (which is stored in the Session object) until it tried to iterate over it in the view. I solved this by using the .ToList () extension method to force loading into the controller.

+1


a source







All Articles