Reputation: 886
I get the following error in the production environment
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the configuration\system.web\httpModules section in the application configuration.
The following things I have tried as of now
machine.config
and web.config
, both have enableSessionState="true"
enableSessionState="true"
to pages in web.config
<httpmodules>
sectionenableSessionState="true"
in page directiveNote: When I try to debug the code in Dev environment, everything works fine as it should.
Can anyone help me out getting over this issue, I just can't figure out a way out of it.
Upvotes: 1
Views: 30573
Reputation: 570
I know this is a late response but I just want to add how I fixed the same problem.
First I want to emphasize that I'm using web forms, not MVC - this may not work for MVC.
I created a web form that contained the class ContactUser and I created my own constructor so it looked like:
public ContactUser(String to, bool isUser) { ... }
And in this I tried to access a session variable:
String user = Session["username"]
It turns out that you CANNOT use the session state in the constructor of a class, but you can use it in other functions that you write and in the protected void Page_Load(object sender, EventArgs e) procedure. So once I moved session state out of the constructor into the page load procedure everything worked :)!
Hope this helps anyone that runs into the same problem :D!
Upvotes: 1
Reputation: 6748
What does your session state config look like? You probably want to be set up to use inproc session handling.
http://msdn.microsoft.com/en-us/library/ms178586.aspx
Upvotes: 5