title: ASP.NET MVC - Session state not passed -> breakpoints not working
body: <p><strong>Problem fixed, see below</strong></p>
  
  <p>What I'm doing is this:</p>
  
  <p>Generate random number -> store it in a session -> pass it to facebook with the 'state' parameter of Facebook's OAuth service -> verify that the returned state is the same as the state in my session (this is done for CSRF protection).</p>
  
  <p>This always worked, no problem. But somehow, it's not working any longer (the Session seems to be empty because I'm getting a NullReferenceException when I try to read it). I probably changed something, but I can't find out what.</p>
  
  <p>I tried setting breakpoints in the part of the code where the state is returned by facebook, but somehow it will never hit the breakpoints... The code between my breakpoints get executed, but my breakpoints are not hit.</p>
  
  <p>This is the code that is executing everything:</p>
  
  <pre><code>public ActionResult SignUpButton()
  {
      int random = RandomHelpers.GetRandomInteger(null);
      Session.Add("facebookState", random.ToString(CultureInfo.InvariantCulture));
  
      ViewBag.Uri = "https://www.facebook.com/dialog/oauth?" +
          "client_id=" + _facebookAuthenticationService.GetAppId() + 
          "&amp;redirect_uri=" + _facebookAuthenticationService.GetReturnUri() + 
          "&amp;scope=email" +
          "&amp;state=" + random;
  
      return PartialView();
  }
  
  public ActionResult Register()
  {
      string error = Request.QueryString["error"];
      string state = Request.QueryString["state"];
      string originalState = Session["facebookState"].ToString();
  </code></pre>
  
  <p>(I removed the rest for brevity). The SignUpButton function returns a partial view containing a button with the sign up URL that leads to facebook. Facebook returns to localhost:xxx/Account/Register (that's the Register function), this functions gets hit (although that breakpoints in Register don't do anything), and an exception is thrown on the Session["facebookState"].ToString() part.</p>
  
  <p>This is what my session-related settings in web.config look like:</p>
  
  <pre><code>&lt;sessionState mode="InProc"&gt;
    &lt;providers&gt;
      &lt;add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;
    &lt;/providers&gt;
  &lt;/sessionState&gt;
  </code></pre>
  
  <p>I just can't figure it out. I already rewritten the code so that it no longer produces errors and returns data from the facebook graph API, but it's just not acceptable that I can't debug that part of the code (for the record: breakpoints in the SingUpButton method <em>are</em> hit).</p>
  
  <p>I hope anyone can help me out. Thanks in advance!</p>