title: Facebook .NET SDK: How to authenticate with ASP.NET MVC 2
body: <p>I am trying to get the grip on the Facebook SDK and at the same time transitioning from ASP.NET forms to MVC (finally). So please bear with me .. </p>
  
  <p>I have created two controller actions:</p>
  
  <p>FBLogon is execetued when the user clicks on the FB login button on the form. 
  He is then redirected to the FB login page.</p>
  
  <p>Afterwards he gets sent back to the FBAuthorize page, which is supposed to parse the returned url for the access token. I get something like:</p>
  
  <p><a href="http://localhost:5000/account/FBAuthorize#access_token=199143326771791|827213759889396d5408fee6-100001815992604|BmYchAOMqSoZ2L0TYgCrtpoKP3M&amp;expires_in=0" rel="nofollow">http://localhost:5000/account/FBAuthorize#access_token=199143326771791|827213759889396d5408fee6-100001815992604|BmYchAOMqSoZ2L0TYgCrtpoKP3M&amp;expires_in=0</a></p>
  
  <p>The problem I see, is that as the access_token is passed behind a #, asp.net cannot parse it on the server. Am I doing something fundamentaly wrong?</p>
  
  <p>Code follows:</p>
  
  <pre><code>    public ActionResult FBLogon()
      {
          var settings = ConfigurationManager.GetSection("facebookSettings");
          IFacebookApplication current = null;
  
          if (settings != null)
          {
              current = settings as IFacebookApplication;
              if (current.AppId == "{app id}" || current.AppSecret == "{app secret}")
              {
                  return View();
              }
          }
  
          string[] extendedPermissions = new[] { "publish_stream", "offline_access" };
          var oauth = new FacebookOAuthClient { ClientId = current.AppId, RedirectUri = new Uri("http://localhost:5000/account/FBAuthorize") };
          var parameters = new Dictionary&lt;string, object&gt;
                  {
                      { "response_type", "token" },
                      { "display", "page" }
                  };
  
          if (extendedPermissions != null &amp;&amp; extendedPermissions.Length &gt; 0)
          {
              var scope = new StringBuilder();
              scope.Append(string.Join(",", extendedPermissions));
              parameters["scope"] = scope.ToString();
          }
  
  
          var loginUrl = oauth.GetLoginUrl(parameters);
          return  Redirect(loginUrl.ToString());
      }
  
  
      public ActionResult FBAuthorize()
      {
  
          FacebookOAuthResult result;
          if (FacebookOAuthResult.TryParse(Request.Url, out result))
          {
              if (result.IsSuccess)
              {
                  var accesstoken = result.AccessToken;
              }
              else
              {
                  var errorDescription = result.ErrorDescription;
                  var errorReason = result.ErrorReason;
              }
          }
          return View();
      }
  </code></pre>