title: facebook sdk Asp.net and using "Getting Started with the Facebook SDK for .NET and ASP.NET"
body: <p>I am trying to create my first facebook sdk Asp.net and using "Getting Started with the Facebook SDK for .NET and ASP.NET" as a guide located here: </p>
  
  <ul>
  <li><a href="http://facebooksdk.net/docs/web/getting-started/" rel="nofollow noreferrer">http://facebooksdk.net/docs/web/getting-started/</a></li>
  </ul>
  
  <p>The problem I am having is that after the FB.init() and FB.Event.subscribe() I don't think the function in the event ever gets called, so there is no post back to my Webform1.aspx so I can get the accessToken. </p>
  
  <p>I did read this post but they had a different problem with breaking out of the login loop:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/15230134/login-with-facebook-c-sharp">Login with Facebook C#</a></li>
  </ul>
  
  <p>Here are the events that are happening when I execute the WebForm1.aspx:</p>
  
  <ol>
  <li>I put breakpoints at various places</li>
  <li>I hit F5 in VS 2012 to Run</li>
  <li>It loads WebForm1.aspx</li>
  <li>void Page_Load is correctly called</li>
  <li>FB.init() is called</li>
  <li>FB.Event.subscribe() is called</li>
  <li>The facebook login image is displayed on WebForm1.aspx</li>
  <li>I click on the facebook login image</li>
  <li><a href="https://www.facebook.com/login.php" rel="nofollow noreferrer">https://www.facebook.com/login.php</a> is displayed.</li>
  <li>I provide the credentials I used to obtain the AppID</li>
  <li>I click Login button in the lower right corner</li>
  <li>I get a dialog that states "The page you are viewing is trying to
   close the window. Do you want to close this window?"</li>
  <li>I choose Yes</li>
  <li>It brings me back to WebForm1.aspx</li>
  <li>void Page_Load is not called, as there is no postback</li>
  <li><p>There is no posted value in accessToken.</p>
  
  <pre><code>&lt;script&gt;
  window.fbAsyncInit = function () {
      FB.init({
          appId: '6453703688*****', // App ID
          status: true, // check login status
          cookie: true, // enable cookies to allow the server to access the session
          xfbml: true  // parse XFBML
      });
  
      alert("about to subscribe to event");
      // Additional initialization code here
      FB.Event.subscribe('auth.authResponseChange', function (response) {
          alert(response.status);
          if (response.status === 'connected') {
              // the user is logged in and has authenticated your
              // app, and response.authResponse supplies
              // the user's ID, a valid access token, a signed
              // request, and the time the access token 
              // and signed request each expire
              var uid = response.authResponse.userID;
              var accessToken = response.authResponse.accessToken;
  
              // TODO: Handle the access token
              // Do a post to the server to finish the logon
              // This is a form post since we don't want to use AJAX
              var form = document.createElement("form");
              form.setAttribute("method", 'post');
              //form.setAttribute("action", '/FacebookLogin.ashx');
              form.setAttribute("action", 'WebForm1.aspx');
  
              var field = document.createElement("input");
              field.setAttribute("type", "hidden");
              field.setAttribute("name", 'accessToken');
              field.setAttribute("value", accessToken);
              form.appendChild(field);
  
              document.body.appendChild(form);
              form.submit();
  
          } else if (response.status === 'not_authorized') {
              // the user is logged in to Facebook, 
              // but has not authenticated your app
              alert("has not authenticated your app");
          } else {
              // the user isn't logged in to Facebook.
              alert("user isn't logged in to Facebook.");
          }
      });
  };
  
  
  // Load the SDK Asynchronously
  (function (d) {
      var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
      if (d.getElementById(id)) { return; }
      js = d.createElement('script'); js.id = id; js.async = true;
      js.src = "//connect.facebook.net/en_US/all.js";
      ref.parentNode.insertBefore(js, ref);
  }(document));
  </code></pre>
  
  <p></p></li>
  </ol>