按照这个例子,我也遇到了同样的问题,我的问题原来是在我的 FacebookLogin.ashx 处理程序页面上,我重定向回原来的 aspx 页面,该页面包含我的 JavaScript 代码。输入此代码后,JavaScript 再次执行我的身份验证,从而使我陷入无限循环。
我最终做的是从这里获取一些 JavaScript 的副本,它为您提供 JavaScript 中的持久会话变量。并在提交帖子的代码周围放置一个条件。这样我只打了一次 FacebookLogin.ashx 处理程序,不会让我陷入循环。
这是我正在使用的代码:
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;
if (sessvars.fbauthenticated == undefined) {
sessvars.fbauthenticated = "1";
// 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", '/FacebookLogin.ashx');
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.
}
});
if (sessvars.fbauthenticated == undefined) {的条件行阻止我的代码多次发布到服务器。
希望这可以帮助