【发布时间】:2014-04-18 12:24:04
【问题描述】:
从 Facebook JS sdk 调用 FB.logout 后,我需要触发我的服务器端代码。这是我的 html 的外观
<asp:LinkButton ID="lbtnSignOut" runat="server" Text="Sign Out" OnClientClick="return Logout();" OnClick="lbtnSignOut_Click"></asp:LinkButton>
还有js代码
function Logout() {
var currentToken = "<%= Session["AccessToken"]%>";
if (currentToken != null && currentToken != '') {
FB.logout(function (response) {
});
}
return true;
}
随后在服务器端代码中,我清除所有应用程序特定会话并使用 FormsAuthentication 注销调用将用户注销并重定向到不同的页面。
现在的问题是,当我从 js 函数返回 true 时,服务器端代码会触发而不等待 fb.logout 完成调用并且用户令牌不会过期并且用户是在我从标准代码中选择的页面加载中自动登录回 FB.Event.subscribe('auth.authResponseChange', function (response) {}; 调用。
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
//SUCCESS
//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 currentToken = "<%= Session["AccessToken"] %>";
if (currentToken == null || currentToken == '') {
// 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 accessToken = response.authResponse.accessToken;
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') {
//FAILED
console.log('User cancelled login or did not fully authorize.');
}
else {
//UNKNOWN ERROR
console.log('Logged Out.');
}
});
};
如果我将值设置为 false,用户将从 facebook 注销,但我的自定义代码不会触发。
所以我的问题是如何在 facebook js sdk 注销代码触发后调用服务器端代码?
任何帮助或指点将不胜感激!!!
帕里托什
【问题讨论】:
标签: javascript asp.net facebook session facebook-c#-sdk