If I set
@ENABLESESSIONSTATE = false
then
session("foo") = "bar"
then the result is
Microsoft VBScript runtime error '800a0114'
Variable is undefined 'Session'
... file and line no
It would usually indicate a mistaken assumption regarding program flow and I would trace and fix the issue.
However, in a specific set of circumstances I have a case where a piece of code that uses session is always invoked first on every page request. It is to do with performance monitoring.
This code includes a fork - if the user has a session we go one way, if not we go another.
But of course where the users session is absent because we introduced some code that runs with session disabled, we get the crash.
I could solve it with
on error resume next
session("foo") = "bar"
if err.number <> 0 then
' do the no-has-session fork
else
' do the has-session fork
end if
on error goto 0
But I wondered if there is a less hacky approach.