I’ve been working with Facebook C# SDK, though there’s one thing I haven’t been able to achieve:
Scenarios:
Scenario 1: User is NOT signed in to Facebook.com. User visits mysite.com. Mysite.com shows Facebook Connect button. User clicks the button to log in, and is redirected to mysite.com/mainsite.
Scenario 2: User is signed in to facebook.com. User then visits mysite.com. User is redirected to mysite.com/mainsite.
Scenario 3: User is logged in to mysite.com with facebook. User closes session inside facebook.com. Mysite.com logs out the user.
Problem:
Scenario 1 and 3 work. But for some reason, facebook c# sdk can only do scenario 2 after refreshing the mysite.com once.
I downloaded the samples. And yes. It happens in the samples too.
I open session in facebook.com. Then visite mysite.com. Nothing happens. No log in. Then I refresh mysite.com and bam. I’m logged in.
Shouldn’t it detect if there’s a session on the first page load? Why doesn’t it? Is it possible? How?
I’ve seen no working example of this automatic log in using facebook c# sdk.
Note: User has already given required permissions to app.
Note: I’m currently working with SDK samples.
You will need to do this using Javascript. You can detect the state of a user with the following code when your page loads (note this is Javascript on the client):
You can read more about this here: https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/