NullReferenceException when adding value to session
<p>I need to store a collection of strings in session, and I have a web method that I'm calling through a jQuery ajax call:</p>

<pre><code>[WebMethod]
public string AddIdToSession(string userId)
{
    List&lt;string&gt; userIds = new List&lt;string&gt;();

    if (HttpContext.Current.Session != null &amp;&amp; 
        HttpContext.Current.Session["userIds"] != null)
    {
        userIds = (List&lt;string&gt;)Session["userIds"];
        userIds.Add(userId);
        HttpContext.Current.Session["userIds"] = userIds;
    }
    else
    {
        userIds.Add(userId);
        HttpContext.Current.Session.Add("userIds", userIds);  // error here
    }

    return userId;
}
</code></pre>

<p>I'm getting an error when I try to add the id to session:</p>

<blockquote>
  <p><strong>Object reference not set to an instance of an object.</strong></p>
</blockquote>

<p>Am I doing this wrong?</p>
