这是我网页上的脚本:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: '419349611446911', // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
// Additional initialization code here
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
// TODO: Handle the access token
// Do a post to the server to finish the logon
// This is a form post since we don't want to use AJAX
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action", '@Url.Action("FacebookLogin", "Account")');
var field = document.createElement("input");
field.setAttribute("type", "hidden");
field.setAttribute("name", 'accessToken');
field.setAttribute("value", accessToken);
form.appendChild(field);
document.body.appendChild(form);
form.submit();
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
};
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
</script>
这是我的:LogOnPartial
:
@if(Request.IsAuthenticated) {
<text>Hola, <strong>@User.Identity.Name</strong>!
[ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
else {
<div class="fb-login-button" data-show-faces="false" data-width="200" data-max-rows="1"></div>
}
当我更改为auth.login
单击登录按钮时,不会登录甚至重定向到任何地方。只是加载的一小段闪光,没有别的。当我使用 时auth.authReponseChange
,我可以使用 Facebook 正确登录,但页面会一遍又一遍地重新加载。
我要问的是,我该如何解决这个错误?为什么auth.authResponseChange
每次都会触发事件?
例子:
我退出本地网站:
FormsAuthentication.SignOut();
即便如此,Facebook 按钮也会自动让我登录,然后循环继续。什么是触发登录按钮单击?