3

My app sometimes calls Server.Transfer in the Application_OnPostAuthenticateRequest event of the global.asax to act as kind of url rewite. When this happens and I need to access Session I get an HttpException: "Session state can only be used when enableSessionState is set to true..." I am assuming this is happening because of the event I am calling Server.Transfer. Is that why I am getting the exception? When should I do the transfer?

Adam Crossland
  • 14,198
  • 3
  • 44
  • 54
Mike
  • 5,437
  • 7
  • 45
  • 62
  • I think session variable are available after execution of Session_Start – Emmanuel N Feb 29 '12 at 14:31
  • Yes it is created then but is it accessible in all events of subsequent requests? FYI I think I am on the wrong track here because I tried a few different events and I'm getting the same exception. Also I only get it when I have to call Server.Transfer. – Mike Feb 29 '12 at 14:41

1 Answers1

8

The PostAuthenticateRequest occurs before the AcquireRequestState and the session state should only be available after this event is raised, so if you need to access session state for the request you need to wait for that event.

See this page as a reference.

  1. ...
  2. Raise the PostAuthenticateRequest event.
  3. ...
  4. Raise the AcquireRequestState event.
  5. ...
João Angelo
  • 56,552
  • 12
  • 145
  • 147
  • Thanks for the reference but I am still getting the exception no matter when I call server.transfer. Is there no session because /blog/someentry does not load up a handler at all? – Mike Feb 29 '12 at 16:19