2012-07-24 65 views
-1

这是我的UserLogin.aspx页面代码,其中包含Facebook用户的身份验证,问题是我在会话中维护令牌,后来我在Default.aspx上使用它。如果你看到这一行Session [“facebook_token”] = authToken;Facebook集成会话问题

在我的Default.aspx页面加载时,我已经放置了这段代码,但是当我到家或默认页面时,它给了我空值。

if (Session["facebook_token"] != null) 
     lblUserName.Text = Session["facebook_token"].ToString(); 


using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using SocialMediaModel; 
using Facebook.Components; 

public partial class UserLogin : System.Web.UI.Page 
{ 
FacebookService _fbService = new FacebookService(); 
private const string FACEBOOK_API_KEY = "551810942508804"; 
private const string FACEBOOK_SECRET = "b63b8cca428b42935e6eab59976367b1"; 

protected void Page_Load(object sender, EventArgs e) 
{ 
    // ApplicationKey and Secret are acquired when you sign up for 
    _fbService.ApplicationKey = FACEBOOK_API_KEY; 
    _fbService.Secret = FACEBOOK_SECRET; 
    _fbService.IsDesktopApplication = false; 

    string sessionKey = Session["facebook_session_key"] as String; 
    string userId = Session["facebook_userId"] as String; 

    string authToken = Request.QueryString["auth_token"]; 

    Session["facebook_token"] = authToken; 

    // We have already established a session on behalf of this user 
    if (!String.IsNullOrEmpty(sessionKey)) 
    { 
     _fbService.SessionKey = sessionKey; 
     _fbService.UserId = userId; 
    } 
    // This will be executed when facebook login redirects to our page 
    else if (!String.IsNullOrEmpty(authToken)) 
    { 
     _fbService.CreateSession(authToken); 
     Session["facebook_session_key"] = _fbService.SessionKey; 
     Session["facebook_userId"] = _fbService.UserId; 
     Session["facebook_session_expires"] = _fbService.SessionExpires; 
    } 
    // Need to login 
    else 
    { 
     Response.Redirect(@"http://www.facebook.com/login.php?api_key=" + 
     _fbService.ApplicationKey + @"&v=1.0"); 
    } 


    } 
} 

回答

0

string authToken = Request.QueryString["auth_token"];

Session["facebook_token"] = authToken;

看起来你正在执行的每个页面加载这些线(?) - 没有检查是否有连此名称的GET参数。