"authtoken & session if elseif else" on ALL pages??

Oct 30, 2007 at 1:53 PM
Hi i've got a few pages working but i'm still not sure weather to put the if elseif else that controls the sessions on all pages or not?

I would be ok wiht it on all pages except when i try and start on a page that is not default.aspx i think i get redirected through facbook/login which then redirects to default.aspx on my site with the location still saying myapp/other.aspx.

Is there a way to pass fb login page the page i would like it to redirect to?

What do you think is the best way to deal with this?

Oct 30, 2007 at 2:47 PM
What exactly do you mean my putting the if elseif else on all pages? Are you copy-and-pasting the same code onto each of your web pages? Also, are you getting this code from one of the CanvasBase pages, or somewhere else?

In general, yes, on each page you will somehow have to detect your session and get a session key so that you can talk to Facebook. However, it should only redirect to Facebook's login page once, so something in your authentication process must not be getting saved correctly. The current preferred way to do all this with the toolkit is to have your page inherit one of the canvas base pages, and call their PageLoad method in your own page's PageLoad. That way, all the session work should be taken care of for you. Are you using some other way of doing this?
Oct 30, 2007 at 3:44 PM
yes currently i'm just copying and pastein the ifelseifelse into all page loads, tried putting it in the pageload of the master but it seems to be fired AFTER the current pages pageload?!
Anyway the main problem i have is that if the page is redirectin to the login , then facebook redierct back to my default.aspx page and not the current page.
i'm using session variable to hold the sessionkey and userid, maybe they are timing out, this is possible. How can i get login to redirect back to the correct page???

Oct 30, 2007 at 4:22 PM
Looks like the login page can take a "next" parameter, which will be appended to the end of your callback url after the user logs in. The documentation on that is here: http://developers.facebook.com/documentation.php?v=1.0&doc=auth.

You shouldn't have to log in every time you go to a new page, though. That sounds like a problem that should probably be fixed.
Oct 30, 2007 at 5:18 PM
what if the session is timing out half way through a user doing something. I guess then the else would redirect out and back to the callback which is not what i want, maybe i need a dummy callback that just redirects depending on the next= parameter??? what do you think?
Oct 30, 2007 at 6:04 PM
No, as I understand it, the next parameter can take a page name (or anything else you wish to add to the end of your callback url), and so it will do all the redirecting for you, and you won't have to make a dummy callback yourself. For example, if you are currently on, let's say, FooPage.aspx and you have gotten to the point where you discover that your session has expired, you just redirect to the login page, with next="FooPage.aspx". Then, once the login is done, it should take you back to FooPage.aspx right away. The URL it takes you to will be something like http://www.mycallback.com/FooPage.aspx, where http://www.mycallback.com/ is your callback URL, and FooPage.aspx is your next parameter, as mentioned. Try that and let me know how it works. Now that I think about it, I may need to make a similar fix in the toolkit canvas base pages.
Oct 30, 2007 at 6:25 PM
Thats great, thanks for that,
It seems people are inheriting the canvas base page????
do you mean something like
public partial class invite : canvasbasepage

where can i find canvasbasepage?
what benefits do i get doing this?

Thanks mate
Oct 30, 2007 at 6:39 PM
If invite is the name of the class for your web page, then yes, that's what I mean. The base pages are in the WebControls dll. So, if you're doing an IFrame app, you'll want to inherit CanvasIFrameBasePage, or if you're doing FBML, inherit CanvasFBMLBasePage.

I almost forgot to mention, but these are used specifically for building canvas pages on Facebook, not for just standalone web apps.

The advantage is that you don't have to do all that if/else if/else stuff on every page - the base page does it for you. That way, all you have to do is provide your API key and secret, and the page gives you a full, connected FacebookService component that you can start using right away. It takes care of redirecting if your session has ended, getting a session from an auth token, etc.
Nov 1, 2007 at 4:07 AM
To put the auth code in your master page, you need to put it in the Page_OnInit method. See: http://msdn2.microsoft.com/en-us/library/dct97kc3.aspx for a handy list of the order of events between masterpages and their content areas.
Nov 1, 2007 at 5:43 PM
thanks skia, i did not know about the Oninit....

Thanks again!