Tuesday, 14 June 2011

ASP.NET C# 4.0 - Facebook Connect Example


Facebook connect example

This is a full example written in ASP.NET 4.0 and Javascript. It uses the Facebook Connect client-side library to authenticate and register uses into a database. This minimalist example explains how to easily integrate Facebook Connect into existing or new web applications.

Technologies used:
- ASP.NET/C#
- Javascript/JQuery
- AJAX
- SQL Server Compact
- Entity Framework
- LINQ

Setup Instructions
1. Add the Developer application to your facebook account and create a new facebook application.

Make sure you run the server on port "8080"... Facebook won't argue with this.
(Note: If you use any other port, other than the standard web traffic ports [80/8080],
then Facebook will throw a blank proxy dialog at you, with no kind of helpful error messages!
The URL will contain something like "xd_proxy"...so make sure it's set at 8080!

The settings you can use are as follows...
[Web Site] > [Site URL] > http://localhost:8080/
[Web Site] > [Site Domain] > localhost
[Facebook Integration] > [Canvas URL] > http://localhost:8080/
[Facebook Integration] > [Tab URL] > http://localhost:8080/
[Advanced] > [Sandbox Mode] > Enable [Note: Must only use developer accounts to test with! or you will get errors]


2. Enter application details into Web.config.

3. Enjoy!


Download
Download Source Files Here

5 comments:

EL said...

Hi,

Can you elaborate the javascript function facebookLogin(), I didn't understand why it didn't allow me to login.

s34n said...

Thanks for the reply,

Can you goto the function and add some debug breakpoints on lines:

FB.login(function (response) {

and

if (response.session) {


You will be able to identify the response and the session data. This will give you a betetr explaiantion as to why its not working for you :)

Sean

Anonymous said...

Hi, god job.
I start the project and it runs with localhost:64xxx . All appId is correct.What should I do for url site on facebook : http://localhost:8080/ or localhost:64xxx beacause after click on login , and accepte authanticate, nothing appears.

Anonymous said...

Hi, god job.
I start the project and it runs with localhost:64xxx . All appId is correct.What should I do for url site on facebook : http://localhost:8080/ or localhost:64xxx beacause after click on login , and acc

YUSUF YILMAZ said...

Hello,
İf your application running in localhost:64xx your facebook url site must be the same.
But be sure about you are using like that format for both site (facebook url site and your site application url site)
http://localhost:64xx/

I hope it helps
cheers