SalGad
SalGad

Reputation: 3011

Session not getting retrieved in Facebook C# SDK example

I am a newbie at ASP.net programming. This is in reference to the Facebook C# SDK, I have managed to set up all the steps required for authentication on this SDK. However, I keep getting a null from the following code:

(reference: http://csharpsdk.org/docs/web/getting-started#5)

var accessToken = Session["AccessToken"].ToString(); //This line returns null and crashes
var client = new FacebookClient(accessToken);
dynamic result = client.Get("me", new { fields = "name,id" });
string name = result.name;
string id = result.id;

Just like in the example, I had set up a generic handler to set up the session variable to be stored in the HttpContext.Session object.

I even tried to modify the offending line to directly access the HttpContext and retrieve the access token:

var accessToken = HttpContext.Current.Session["AccessToken"].ToString();

but this yielded the same result.

Have I missed out something in the webconfig or is there some other way I can store the access token when shifting from the handler to the log in page?

Upvotes: 1

Views: 1256

Answers (2)

Ray Suelzer
Ray Suelzer

Reputation: 4107

Make sure in your Facebook developer settings that you do not have query string selected for your app as auth token paramenter!!!

This is the default mode and this wont work unless you do the following:

http://developer.facebook.com

Open your app page.

Then go Settings --> Auth Dialog --> Auth Token Parameter and select URI Fragment.

100% sure this is your problem. It's not included in any literature I found, and it's a damn shame.

Upvotes: 1

Kevin Main
Kevin Main

Reputation: 2344

If it is returning null then I would assume that the Session value is not being set - have you debugged to make sure the code which sets the session is being hit?

Looking at the linked article - it uses a HttpHandler to do this bit but does not mention anything about registering it in the Web.Config - have you done this? If not see here http://msdn.microsoft.com/en-us/library/46c5ddfy.aspx

Upvotes: 0

Related Questions