{"id":2064,"date":"2012-10-31T14:20:00","date_gmt":"2012-10-31T14:20:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2012\/10\/31\/deploying-your-first-facebook-app-on-azure-using-asp-net-mvc-facebook-template\/"},"modified":"2012-10-31T14:20:00","modified_gmt":"2012-10-31T14:20:00","slug":"deploying-your-first-facebook-app-on-azure-using-asp-net-mvc-facebook-template","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/deploying-your-first-facebook-app-on-azure-using-asp-net-mvc-facebook-template\/","title":{"rendered":"Deploying your first Facebook App on Azure using ASP.NET MVC Facebook Template"},"content":{"rendered":"<p>Today we announced the preview for <a href=\"http:\/\/www.asp.net\/vnext\">ASP.NET Fall 2012 Update<\/a> and one of the cool features we added to the update is the <strong>Facebook Application Template<\/strong>. This template includes a new library that makes it easier to develop Facebook applications using ASP.NET MVC.<\/p>\n<p>Here is the <a href=\"http:\/\/www.asp.net\/vnext\/overview\/fall-2012-update\/facebook-application-template-tutorial\">tutorial<\/a> to learn more about this template. In this post, I won\u2019t be going too deep into the implementation of the app, instead I\u2019ll focus on the deployment of the app on Azure.<\/p>\n<p>Disclaimer: This template is still in a preview state. The APIs could change significantly before the final release.<\/p>\n<h2>Prerequisites<\/h2>\n<p><a href=\"http:\/\/www.windowsazure.com\/en-us\/develop\/vs11\/\">Visual Studio 2012 + Azure SDK<\/a><\/p>\n<p><a href=\"http:\/\/www.asp.net\/vnext\">ASP.NET Fall 2012 Update (preview)<\/a><\/p>\n<p><a href=\"http:\/\/www.windowsazure.com\/en-us\/\">A Windows Azure account<\/a><\/p>\n<p><a href=\"https:\/\/www.facebook.com\/\">A Facebook account<\/a><\/p>\n<h2>Getting started<\/h2>\n<p>Here we are going to deploy the project created from the Facebook Application template to Azure. Once the project is deployed, the app should display a page showing the authenticated user and some of his\/her friends.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"Capture\" border=\"0\" alt=\"Capture\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/1263.Capture_thumb_5933A6F7.png\" width=\"554\" height=\"398\" \/><\/p>\n<h2>Step 1: Create a new MVC Facebook template<\/h2>\n<p>Go to <strong>New Project<\/strong> \u2013&gt; <strong>ASP.NET MVC 4 Web Application<\/strong>, and then select the <strong>Facebook Application<\/strong> template.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/7245.image_thumb_783DFCC2.png\" width=\"554\" height=\"270\" \/><\/p>\n<p>Once the project is created, you can open HomeController.cs to get an idea of what it does. First, note that the Index action has a [FacebookAuthorize] attribute which will ensure that the request is signed (coming from Facebook). On the [FacebookAuthorize] attribute you can also specify additional permissions that you would like the user to grant to your application. Second, the parameters (user, userFriends) on the action are populated (by custom model binders) when the action is invoked so you can just display them on the view.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/6663.image_thumb_3807E348.png\" width=\"554\" height=\"183\" \/><\/p>\n<h2>Step 2: Create a new App on Facebook<\/h2>\n<p>Login into [https:\/\/developers.facebook.com\/apps][7] to create a new application. The \u201cApp Name\u201d needs to be unique and you can provide the optional \u201cApp Namespace\u201d if needed.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/8814.image_thumb_3EBAECCB.png\" width=\"554\" height=\"176\" \/><\/p>\n<p>Once the app is created, it will be assigned an App ID and an App Secret.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/0003.image_thumb_7E84D350.png\" width=\"554\" height=\"203\" \/><\/p>\n<p>You could paste these values into the Web.config of your new Facebook project created in Step 1. However, it\u2019s recommended that you <strong>specify them on Azure (Step 4) instead of hard coding<\/strong> them in the source.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/6354.image_thumb_2552E991.png\" width=\"554\" height=\"164\" \/><\/p>\n<h2>Step 3: Create a new Web Site on Windows Azure<\/h2>\n<p>Next, we need to create a new \u201cWeb Site\u201d for the application.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/4048.image_thumb_651CD016.png\" width=\"554\" height=\"112\" \/><\/p>\n<h2>Step 4: Configure your application on Azure<\/h2>\n<p>Once the new \u201cWeb Site\u201d is created, click on it and select \u201cCONFIGURE\u201d to provide the app settings. Here we\u2019ll add the following settings. Make sure you SAVE the settings.<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"422\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"200\">\n        <strong>key<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"220\">\n        <strong>value<\/strong>\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"200\">\n        Facebook.AppId\n      <\/td>\n<td valign=\"top\" width=\"220\">\n        \u201cApp ID\u201d from Facebook site\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"200\">\n        Facebook.AppSecret\n      <\/td>\n<td valign=\"top\" width=\"220\">\n        \u201cApp Secret\u201d from Facebook site\n      <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/0804.image_thumb_52D40954.png\" width=\"554\" height=\"580\" \/><\/p>\n<h2>Step 5: Configure your application on Facebook<\/h2>\n<p>Now we need to provide the <strong>Canvas URL<\/strong>. Here you can paste your Azure site URL, e.g. http:\/\/myfirstapplication.azuresites.net\/.<\/p>\n<p>Since October 1st, Facebook [expects your canvas app to be hosted at a secure address][13] (HTTPS). Thus you need to specify the <strong>Secure Canvas URL<\/strong>. If you don\u2019t have a secure address yet, just put something like https:\/\/myfirstapplication.azuresites.net\/ and <strong>enable Sandbox mode<\/strong>. Make sure you save the changes.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/1057.image_thumb_44959064.png\" width=\"554\" height=\"520\" \/><\/p>\n<h2>Step 6: Import the \u201cpublish profile\u201d and publish your Facebook App to Azure<\/h2>\n<p>Now everything should be ready to go. For this last step, you need to download the \u201cpublish profile\u201d of your Web Site in Azure.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/8836.image_thumb_7D403A71.png\" width=\"554\" height=\"199\" \/><\/p>\n<p>Right click on the project and select Publish\u2026<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/8420.image_thumb_5605F13C.png\" width=\"554\" height=\"210\" \/><\/p>\n<p>Import the \u201cpublish profile\u201d you\u2019ve downloaded previously and hit Publish.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/3443.image_thumb_71AA7D32.png\" width=\"554\" height=\"433\" \/><\/p>\n<h2>The result<\/h2>\n<p>You can now browse to the Canvas Page to see the app. The URL of the Canvas Page is listed on your Facebook portal.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/6038.image_thumb_5704B198.png\" width=\"554\" height=\"194\" \/><\/p>\n<p>Upon the first time you access the app, the following dialog will appear asking for permissions to access your basic info and email address.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/6165.image_thumb_71C34447.png\" width=\"554\" height=\"249\" \/><\/p>\n<p>Click \u201cGo to App\u201d to grant the permissions, and you should see the home page showing your basic info and some of your friends.<\/p>\n<p><img decoding=\"async\" style=\"border-right-width: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px;padding-top: 0px\" title=\"Capture\" border=\"0\" alt=\"Capture\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2012\/10\/8712.Capture_thumb_18252793.png\" width=\"554\" height=\"398\" \/><\/p>\n<p>Congratulations, you just published your first Facebook application!<\/p>\n<p>Thanks,<\/p>\n<p>Yao<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we announced the preview for ASP.NET Fall 2012 Update and one of the cool features we added to the update is the Facebook Application Template. This template includes a new library that makes it easier to develop Facebook applications using ASP.NET MVC. Here is the tutorial to learn more about this template. In this [&hellip;]<\/p>\n","protected":false},"author":453,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[7333,7414,7415],"class_list":["post-2064","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-asp-net-mvc","tag-facebook-application","tag-windows-azure"],"acf":[],"blog_post_summary":"<p>Today we announced the preview for ASP.NET Fall 2012 Update and one of the cool features we added to the update is the Facebook Application Template. This template includes a new library that makes it easier to develop Facebook applications using ASP.NET MVC. Here is the tutorial to learn more about this template. In this [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/453"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=2064"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2064\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=2064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=2064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=2064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}