WebApp with RC3

Nov 3, 2008 at 9:41 AM
Edited Nov 3, 2008 at 9:43 AM
I've just created a simple WebApp with the following code:

using System;
using System.Configuration;
using facebook;
using facebook.web;

public partial class _Default : CanvasFBMLBasePage
    new protected void Page_Init(object sender, EventArgs e)
        base.ApiKey = ConfigurationManager.AppSettings["ApiKey"];
        base.Secret = ConfigurationManager.AppSettings["Secret"];
        base.Page_Init(sender, e);

        content.InnerText = API.uid.ToString();

Unfortunately uid seems to be 0.

If I add the following line, I get an error:
content.InnerText += API.users.getInfo().first_name;

[NullReferenceException]: Object reference not set to an instance of an object. at _Default.Page_Init(Object sender, EventArgs e) at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnInit(EventArgs e) at System.Web.UI.Page.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) [HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown. at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.default_aspx.ProcessRequest(HttpContext context) in c:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ef7b55d7\a46ab1bf\App_Web_lwhg10nb.0.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Nov 3, 2008 at 1:57 PM
That's because of a change in the default setting for RequireLogin. It used to be set to true by default, which would force you to log into the app before viewing any pages, unless you changed the setting. However, as a result of some other discussions (http://www.codeplex.com/FacebookToolkit/Thread/View.aspx?ThreadId=35399), I decided to change the default value for RequireLogin to false. Long story short, it's basically because I think that makes a little more sense in light of Facebook making apps visible to anyone, not just people who are signed in to the app. Of course, now that I say that, I'm starting to rethink it, but that's how it works for now.

So, in your case, just make sure to run the following before calling Page_Init:

base.RequireLogin = true;
Nov 3, 2008 at 3:12 PM
Thanks for the info, works fine now :)
Nov 4, 2008 at 3:26 PM
Is this the same for the CanvasIFrameMasterPage as it does not seem to contain this property? Or is this just for users that use FBML?

Nov 4, 2008 at 3:58 PM
No, this is just for users that use FBML. The IFrame page has the AutoAdd property, which is somewhat similar. However, now that I look at it, it looks like it defaults to true (which is the opposite of the FBML page).

I think I'm going to add an issue to try to coordinate the work between the FBML and IFrame pages. I hadn't really looked into that code in a while, but it looks like we're duplicating a fair amount of work, and some things are being done a little differently. I think these could each use a bit of cleaning up.