title: How in code to detect if session is enabled rather than just get an error
body: <p>If I set </p>
  
  <pre><code>@ENABLESESSIONSTATE = false
  </code></pre>
  
  <p>then </p>
  
  <pre><code>session("foo") = "bar"
  </code></pre>
  
  <p>then the result is </p>
  
  <blockquote>
    <p>Microsoft VBScript runtime error '800a0114'<br>
    Variable is undefined 'Session'<br>
    ... file and line no</p>
  </blockquote>
  
  <p>It would usually indicate a mistaken assumption regarding program flow and I would trace and fix the issue. </p>
  
  <p>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. </p>
  
  <p>This code includes a fork - if the user has a session we go one way, if not we go another.</p>
  
  <p>But of course where the users session is absent because we introduced some code that runs with session disabled, we get the crash.</p>
  
  <p>I could solve it with </p>
  
  <pre><code>on error resume next 
  session("foo") = "bar"
  if err.number &lt;&gt; 0 then
  
     ' do the no-has-session fork
  
  else
  
     ' do the has-session fork
  end if
  on error goto 0
  </code></pre>
  
  <p>But I wondered if there is a less hacky approach.</p>