Friday, July 23, 2010

Session State not working even though you have enabled it?!

This was a doozie... I was working on a local dev box running Windows Vista and .NET 2.0. I pulled down another developer's web project that uses Session State variables, and when I went to test it, I received this error:

"System.Web.HttpException: Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive..."
I did some sleuthing, and find different recommendations:
  1. Add to your web.config file, within the area.
  2. Add to the same area.
  3. Make sure is in the httpModules area of your root level web.config file (some people said machine.config, not sure which, but I tried both).
  4. Add EnableSessionState="true" to the .aspx @Page directive.
Well, I tried all of these. Yet I still received this error. I opened up IIS Manager and looked at the root level of the site. There's even a configuration panel for "Session State," and "InProc" was already selected. EVERYTHING was turned on, why wasn't it working???

I just figured it out, although I have no idea how or why it was required:
  • In IIS Manager (in IIS7), go to the top level of the website in question.
  • Instead of clicking on the Session State panel, double-click the "Modules" area.
  • Scan that list and see if you have a module for Session State configured (I did not).
  • If not, click the Add Managed Module... button.
  • Type "Session" in the first box (no quotes).
  • In the second box, type "System.Web.SessionState.SessionStateModule" (no quotes)
  • Click the checkbox "invoke only requests to" (at least, that's what I did)
Now try your application again. If you're lucky like me, it just worked!

1 comment:

Ronda said...

Thank you very much for your sharing. It solved my problem.