canvas page showing login button evem if the user is logged in
<p>I have some authentication problem in my app.. its <a href="http://apps.facebook.com/exmpldatetime" rel="nofollow">http://apps.facebook.com/exmpldatetime</a>
I'm using old sdk (v2.0 ) n fbconnect class bt having a problem..</p>

<ol>
<li>user logins.</li>
<li>goes to my app.</li>
<li>canvas page shows connect to facebook login button.</li>
<li>if user clicks this login button or refresh the page it shows hi,username (and this should be the actual case)</li>
<li>now if user goes to home page of account and then goes to app now it dont shows the login button just shows hi,username</li>
</ol>

<p>Why this all is happening?</p>

<p>here is the code for asp page</p>

<pre><code>using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using facebook;
using facebook.web;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        API api = new API();
        fbConnect fbconnect = new fbConnect();
        if (fbConnect.isConnected()) // Check if this application is authenticated
        {
            api.ApplicationKey = fbConnect.ApiKey;
            api.SessionKey = fbConnect.SessionKey;
            api.Secret = fbConnect.SecretKey;
            api.uid = fbConnect.UserID;

            // hide the facebook button
            pnlLogin.Visible = false;

            //Get the data of the signed user.
            string fullName = "&lt;img src=\"" + api.users.getInfo(fbConnect.UserID).pic_small + "\" /&gt; " + " " + " " + "Hi," + " " + api.users.getInfo(fbConnect.UserID).first_name.ToString() + " " + api.users.getInfo(fbConnect.UserID).last_name.ToString();
            lblMessage.Text = fullName;
        }
        else
        {
           pnlLogin.Visible = true;

        }
    }

}
</code></pre>

<p>html code</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Canvas.aspx.cs" Inherits="_Default" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en" lang="en"&gt;
&lt;head id="Head1" runat="server"&gt;
    &lt;title&gt;CanvasPage&lt;/title&gt;
    &lt;script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
        type="text/javascript"&gt;&lt;/script&gt;

    &lt;/head&gt;
&lt;body &gt;
    &lt;form id="form1" runat="server" &gt;

        &lt;div id="login" class="login"&gt;
         &lt;asp:Panel ID="pnlLogin" runat="server"&gt;
            &lt;fb:login-button length="long" onlogin="window.location.reload()"&gt;
                &lt;/fb:login-button&gt;
             &lt;/asp:Panel&gt;
              &lt;table&gt;
                &lt;tr&gt;
                    &lt;td&gt;
                        &lt;asp:Label ID="lblMessage" runat="server" Text="Not authenticated. Click Button to authenticate"&gt;&lt;/asp:Label&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;/table&gt;
        &lt;/div&gt;
        &lt;/form&gt;
&lt;script type="text/javascript"&gt;
        FB.init("API Key", "xd_receiver.htm");
    &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<h2>code for fbconnect class</h2>

<pre><code>using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using facebook;
using facebook.Utility;

public class fbConnect
{

    public fbConnect()
    {}
    public static bool isConnected()
    {
        API api;
        api = new API();
        api.SessionKey = SessionKey;
        api.ApplicationKey = ApiKey;
        api.Secret = SecretKey;
        api.uid = UserID;

        if (api.SessionKey == null)
        {
            return false;
        }
        // can't really tell if the session key we have is still valid
        try
        {
            api.uid = api.users.getLoggedInUser();
        }
        catch (FacebookException)
        {
            // invalid session key found
            ClearFacebookCookies();
            return false;
        }
        return true;
    }
   public static string ApiKey
    {
        get
        { return ConfigurationManager.AppSettings["APIKey"];}
    }
    public static string SecretKey
    {
        get
        {return ConfigurationManager.AppSettings["Secret"];}
    }

    public static string SessionKey
    {
        get
        {return GetFacebookCookie("session_key"); }
    }
    public static void ClearFacebookCookies()
    {
        string[] cookies = new[] { "user", "session_key", "expires", "ss" };
        foreach (var c in cookies)
        {
            string fullCookie = ApiKey + "_" + c;
            if (HttpContext.Current != null &amp;&amp;
                HttpContext.Current.Response.Cookies[fullCookie] != null)
            { HttpContext.Current.Response.Cookies[fullCookie].Expires = DateTime.Now.AddMonths(-2); }
        }
    }

    public static long UserID
    {
        get
        {
            long userID = -1;
            long.TryParse(GetFacebookCookie("user"), out userID);
            return userID;
        }
    }

    private static string GetFacebookCookie(string cookieName)
    {
        string retString = null;
        string fullCookie = ApiKey + "_" + cookieName;
        if (HttpContext.Current.Request.Cookies[fullCookie] != null)
            retString = HttpContext.Current.Request.Cookies[fullCookie].Value;
        return retString;
    }
}
</code></pre>
