
It’s about time for an update on Facebook Application with ASP.NET, using Nikhil Kothari’s Facebook API wrapper for ASP.NET, Facebook.NET. If you want to read about why I’m using Facebook.NET instead of the Facebook Control Toolkit then click here.
I’ve spent a lot of time developing my Facebook application this weekend and I have a few additional pointers that I’d like to throw out for any Facebook.NET developers looking to get started:
- Use Steve Trefethen’s Visual Studio.NET starter kit for Facebook.NET – This starter kit is a handy package for jump starting a Facebook.NET application from scratch. I’ve written most of my Facebook application using Steve’s starter kit as a foundation (I ditched my botched FBML attempt and re-did the entire UI as an iframe.)
- Develop and debug your application as an <iframe> application – Take it from me, developing an FBML application is a pain in the ass for the following reasons:
- FBML is very strict
- Your FBML applications have to be run off of a server that Facebook can connect to, so a lot of your localhost debugging options disappear if you are behind a firewall like me.
- FBML obfuscates any HTTP error messages, thus it can be very hard to track down and locate error messages when something goes wrong. I actually developed a great solution to this problem but still it was just easier to switch to an iframe.
- Facebook’s Stylesheets can mess with your graphical elements a lot when you develop with FBML; using an iframe gives a clean slate (but you also have to try and then create your own styles that mesh well with Facebook!).
- You can always develop and test the core of your application as an iframe and then embed it into an FBML wrapper later as an <fb:iframe /> element.
I could go on all day about how much easier it is to work with iframes than FBML, and I may even write an entire post about it, but if you need just one reason, then it’s this: you can debug on your localhost effortlessly with iframes, and not at all with FBML.
- Use strongly-typed references to Master Pages in all of your .aspx files – In my 10 Hot ASP.NET Tips and Tricks for the week of 9/28/2007 article I mentioned an article on master pages. In the subsequent code sample for the article I linked to you can see where the author uses strongly-typed master page references to access controls on the master page via the .aspx pages. If you use Steven Trefethen’s starter kit then you need to implement some sort of strongly-typed reference in order to access the Facebook Application control which will then give you access to the Facebook Application service. All of my .aspx pages connect to Facebook via the master page’s control, and it saves on a lot of code duplication.
- Use <fb:FacebookHyperLink> extensively – One of the problems I had with my <iframe> approach was that my ASP.NET links would all point to my localhost url rather than translate correctly to Facebook’s url.
For instance if my application’s home page were hosted at http://localhost/default.aspx and I wanted to go to my “invite friends” page, invite.aspx, clicking on a link that uses traditional ASP.NET relative-architecture (~/invite.aspx) would land me on http://localhost/invite.aspx, but where I really want to go is to Facebook’s translated address http://apps.facebook.com/myapp/invite.aspx.
<fb:FacebookHyperLink> takes care of this translation for you automatically, and it even adds the correct target property so you can navigate properly via <iframe>. This will save you from a lot of headaches.
- Use the FBML Test Console - If your application sets a box on a user’s profile page, which requires FBML, then you need to make sure you thoroughly test your Facebook application’s FBML output using Facebook’s FBML test console. You will not be able to test FBML rendering on your local machine as there are no desktop tools available for FBML. In addition Facebook changes the FBML standards frequently so even if there was a tool available it would become out of date in relatively short order.
I’ll have some more tips and some code samples available this week as my development continues. I hope you find these helpful.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Comments 12
I’m glad you found it useful and thanks for link back.
Posted 01 Oct 2007 at 1:01 pm ¶Hey Steve,
Thanks for the comment, and it’s no problem; I really like your starter kit! Sorry for spelling your name wrong (which I just corrected); I wrote the article in the wee hours of the morning my spelling took a bit of a nose dive, so my apologies!
Posted 01 Oct 2007 at 1:46 pm ¶No worries, as you can imagine my name is spelled wrong all the time. Thanks for the correction!
Posted 07 Oct 2007 at 10:24 pm ¶Aaron. Thanks for the tips, Steve’s starter kit is tidy!
Posted 10 Nov 2007 at 4:55 pm ¶Hey Aaron
Posted 10 Nov 2007 at 8:01 pm ¶Would you happen to have an example of how you “implemented strongly-typed master page references to access controls on the master page via the .aspx pages”?
I found this comment on debugging FBML on Nikhil’s blog
———————————-
JustinM
Posted on 10/22/2007 @ 7:14 AM
Manjit,
Yes you can debug locally with fbml apps. What I did is get a free dynamic dns (gotdns.com), port forward port 80 (actually in my case port 8080, as some other machine is using 80) directly to my development laptop that has IIS running (Vista Ultimate, note the Application Pool may need to be set to “classic”). Then made a local dns entry in windows\system32\etc\hosts file to have the dns entry point to 127.0.0.1 for resolving url’s that point directly to my site (images). Everything works fine.
Posted 12 Nov 2007 at 3:01 pm ¶Cameron,
Thanks for the GREAT comment. I’m going to post this as it’s own article.
Posted 12 Nov 2007 at 3:10 pm ¶Great and unique article. Thanks for this.
Posted 23 Nov 2007 at 8:39 am ¶It helped me a lot in writing an article Writing Facebook Applications in .NET
Writing Facebook Applications in .NET With Facebook.NET
Very informative article. Thanks!
Posted 17 Dec 2007 at 1:59 am ¶How do I use ? can I use this in an IFrame? I’ve made my application using Steve Trefethen’s Visual Studio.NET starter kit for Facebook.NET as a base. I’d like my Canvas page Menu to be built using the VS 2008 Menu control and sitemap and anyone done this let me know?
m3ntat@gmail.com
Thanks
Posted 07 Jan 2008 at 1:32 pm ¶How do you use the starter kit? You can use it in an IFRAME, and that’s absolutely the best option for building your first Facebook application given that it’s much easier to debug Facebook.NET applications when they’re running as IFrames.
The Canvas Page can be built using the menu control and sitemap; you may have to do your own custom subclass of the menu control in order to make sure that the rendered hyper links are all compatible with the Facebook-domain for your application though. You can probably roll up Facebook.NET’s control into a custom menu control in order to take care of that automatically.
Let me know if you have anymore questions!
Posted 07 Jan 2008 at 3:57 pm ¶thanks for tips.
Posted 25 Jan 2009 at 4:47 am ¶Trackbacks & Pingbacks 1
[...] Just a quick post for today, but a valuable one nonetheless. I have mentioned before how I prefer developing Facebook.NET applications using the Iframe method of implementation, namely because I didn’t think it was possible to debug FBML implementations on the localhost. [...]
Post a Comment