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:
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:
- using System.Threading.Tasks;
- using System.Web.Mvc;
- using Microsoft.AspNet.Mvc.Facebook;
- using Microsoft.AspNet.Mvc.Facebook.Client;
- using FbWebMvcApp.Models;
-
- namespace FbWebMvcApp.Controllers
- {
- public class HomeController : Controller
- {
- [FacebookAuthorize]
- public async Task<ActionResult> Index(FacebookContext context)
- {
- if (ModelState.IsValid)
- {
- var user = await context.Client.GetCurrentUserAsync<MyAppUser>();
- return View(user);
- }
- return View("Error");
- }
-
- // This action will handle the redirects from FacebookAuthorizeFilter when
- // the app doesn
- // The path to this action is defined under appSettings (in Web.config) with the key
- public ActionResult Permissions(FacebookRedirectContext context)
- {
- if (ModelState.IsValid)
- {
- return View(context);
- }
- return View("Error");
- }
- }
- }
Step 2: Run the application