0

I am getting an exception usually at night on a new project of mine. It is deployed to a hosting provider and visable to everyone.

My exception is:

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 <system.web><httpModules> section in the application configuration.

In my web.config there is:

<pages validateRequest="false" enableSessionState="true"
       enableViewStateMac="true" enableEventValidation="true"
       viewStateEncryptionMode="Always">

The exception is happening while getting Session.SessionID within one of my modules. This module is present on all pages in the application.

The application runs fine when I am here at work - but a night when I am not here this happens. I also never got this error while running application on my local dev machine. So I suspect a bot. Or possibly, hosting company shutting down services for some reason?

Is there any way to prevent this from happening? Like

if(Session.Isavailable)

or something I can add to my function in programmatically?

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
duerzd696
  • 304
  • 1
  • 8
  • Are you using memory based session, or sql server for the sessions? I find on MANY hosting providers, the loss of session in memory occurs way too often, so turned on sql server based sessions, and now it be rock solid. If the hosting provider uses load balancing, then you MUST use sql sessions, since the web site then might start running on a different server, and memory is not transferred when that occurs - so you have to use sql server based sessions on my new hosting providers - especially the cloud based ones. – Albert D. Kallal Dec 13 '22 at 17:23
  • This is one a dotnetnuke application - it is not in web.config to tell me in-proc or database or the other one? I know Session.SessionID works because I have a table that records the value - just for a temporary way to identify a user until they log in. They can add stuff to cart - then when logging in I delete from table which records sessionid and then I use real id. – duerzd696 Dec 13 '22 at 17:38
  • Also, I am on a dedicated server - so no shared hosting. – duerzd696 Dec 13 '22 at 17:45
  • Well, any error in code can and will often re-start the app pool, and if that occures, then in-memory session is lost. But, not if you flip the switch to use sql based ones. I had nothing but session issues and problems and loss of session values. Once I turned on sql based sessions, the whole system became rock solid. Often users can survive a server re-boot with sql based sessions. Life is just too short to track down such issues when a super rock solid solution exists for fixing all session issues and problems. – Albert D. Kallal Dec 13 '22 at 20:10

0 Answers0