title: Why Can WebMethod Access Session State Without EnableSessionState?
body: <p>I have a method on a page marked as a <code>[WebMethod]</code> that uses some session state as part of its operation.  After I wrote this code, I suddenly had a flash of memory that you need to use <code>EnableSessionState</code> when you use session state in a <code>[WebMethod]</code> (e.g. see here: <a href="http://msdn.microsoft.com/en-us/library/byxd99hx.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/byxd99hx.aspx</a>).  But it seems to be working fine.  Why?</p>
  
  <p>Sample code behind:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs args) {
      this.Session["variable"] = "hey there";
  }
  [System.Web.Services.WebMethod]
  public static string GetSessionVariable() {
      return (string)HttpContext.Current.Session["variable"];
  }
  </code></pre>
  
  <p>Sample body html:</p>
  
  <pre><code>&lt;script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      function getSession() {
          $.ajax({
              type: 'POST',
              url: 'Default.aspx/GetSessionVariable',
              data: '{ }',
              contentType: 'application/json; charset=utf-8',
              dataType: 'json',
              success: function (msg) {
                  document.getElementById("showSessionVariable").innerHTML = msg.d;
              }
          });
          return false;
      }
  &lt;/script&gt;
  &lt;form id="form1" runat="server"&gt;
      &lt;div id="showSessionVariable"&gt;&lt;/div&gt;
      &lt;button onclick='return getSession()'&gt;Get Session Variable&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>