Solution: Server Error in Facebook Template using Visual Studio 2013

Overview

Recently, I was creating Facebook Template in Visual Studio 2013. I have already created an article on Facebook Template in Visual Studio 2013 Preview. I am using now Visual Studio 2013 new upgraded version.

When I create the Facebook Template in Visual Studio 2013 now, I receive the following error while running the application in the browser:

Server Error in Facebook

Solution

There are some changes made in the Facebook API. We are using the new Facebook API, so we have to modify the template code which is provided by the Facebook Project Template.

You have to follow the steps below:

Step 1: Open the Controllers->HomeController file and edit the code with the following highlighted code:

  1. using System.Threading.Tasks;  
  2. using System.Web.Mvc;  
  3. using Microsoft.AspNet.Mvc.Facebook;  
  4. using Microsoft.AspNet.Mvc.Facebook.Client;  
  5. using FbWebMvcApp.Models;  
  6.    
  7. namespace FbWebMvcApp.Controllers  
  8. {  
  9.     public class HomeController : Controller  
  10.     {  
  11.         [FacebookAuthorize]  
  12.         public async Task<ActionResult> Index(FacebookContext context)  
  13.         {  
  14.             if (ModelState.IsValid)  
  15.             {  
  16.                 var user = await context.Client.GetCurrentUserAsync<MyAppUser>();  
  17.                 return View(user);  
  18.             }   
  19.             return View("Error");  
  20.         }  
  21.    
  22.         // This action will handle the redirects from FacebookAuthorizeFilter when  
  23.         // the app doesn't have all the required permissions specified in the FacebookAuthorizeAttribute.  
  24.         // The path to this action is defined under appSettings (in Web.config) with the key 'Facebook:AuthorizationRedirectPath'.  
  25.         public ActionResult Permissions(FacebookRedirectContext context)  
  26.         {  
  27.             if (ModelState.IsValid)  
  28.             {  
  29.                 return View(context);  
  30.             }   
  31.             return View("Error");  
  32.         }  
  33.     }  
  34. }  

Step 2: Run the application

Facebook Template in VS 2013

Next Recommended Reading Online Templates In Visual Studio 2015