Created
July 5, 2011 18:11
-
-
Save prabirshrestha/1065450 to your computer and use it in GitHub Desktop.
Facebook Connect with ASP.NET MVC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AccountController : Controller | |
{ | |
public ActionResult Login(string returnUrl, string scope) | |
{ | |
if (!Url.IsLocalUrl(returnUrl)) | |
{ | |
returnUrl = "/"; | |
} | |
ViewData["returnUrl"] = returnUrl; | |
ViewData["scope"] = scope; | |
return View(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="fb-root"> | |
</div> | |
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
FB.init({ | |
appId: '@Facebook.FacebookApplication.Current.AppId', cookie: true, status: true, xfbml: true | |
}, "/xd_receiver.htm"); | |
FB.Event.subscribe('auth.login', function () { | |
window.location = '@ViewData["returnUrl"]'; | |
}); | |
</script> | |
<fb:login-button @if (!string.IsNullOrWhiteSpace((string)ViewData["scope"])){<text>perms="@ViewData["scope"]"</text>}>Login to Facebook</fb:login-button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><body> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script></body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make sure to add the following in html tag of the page