Click here to Skip to main content
13,357,219 members (73,755 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 23 Jul 2012

NuGet Package: Facebook helper in MVC Razor

, 23 Jul 2012
Rate this:
Please Sign up or sign in to vote.
The era of global connectivity has begun. Social networking being the first step in this process, most of the latest technologies are coming up with different kinds of support for social network sites.

The era of global connectivity has begun. Social networking being the first step in this process, most of the latest technologies are coming up with different kinds of support for social network sites.
One of the famous of such social networks is Facebook.

Recognized this button. Yes, in this post we will see how to implement this kind of functionality in your MVC Razor application with a single line of code. Even Microsoft recognized the importance of social networking and thus introduced different helper classes for different social network sites.

Step 1: Create a MVC Razor application. Go to references and right click and select "Nuget Package Manager".

NuGet Plugin/Package Manager will appear.

Step 2: Search with Facebook in Nuget Manager Console. Select Facebook.Helper Nuget package.

Click on install button. Once it is installed, a green color tick mark will appear saying this Package is installed on your machine. Restart Visual Studio for after effects.

Step 3: It is very important to know what happened because of step 2. For that reopen the project and see that you will have a "App_Code" folder newly created in your solution. Open it and see, you will have a "Facebook.Cshtml" file.

It will have all the Helper methods which will be used to handle Facebook infrastructure in your application.

Step 4: Now go to your Index Page, add the below line


There are many other helper methods available with Facebook Helper class created. But for time being we test only Like Button. Now execute the application and see the result.


Step 5: Before going to see why we got this error, we need to know about two DLLs. WebMatrix.Data.dll : Provides methods and properties that are used to access and manage data that is stored in a database.

WebMatrix.WebData.dll : Provides security and authentication features for ASP.NET Web Pages applications, including the ability to create user accounts, log users in and out, reset or change passwords, and perform related tasks.

Now, from significance of these two dlls, you will understand that the Facebook helper class need the support of these two DLLs to log in the user and get/post the data to Facebook application. The above error is due to lack of these two dlls.

Step 6: Now reffer these DLLs and mark them copy local true. Reason being, these dlls need to be in local bin folder, to make Facebook helper infrastructure work.

Step 7: Now before execution, let me tell you how Facebook Login work. If you are trying to access Facebook for the first time, Facebook will ask you to authenticate. Once after authentication, the credentials will be saved as a cookie on your machine. So, next time when you hit Facebook, it will check for that cookie, and if present, it will read the account details from cookie and take you directly to home page without authentication.

Step 8: Execute and see out put to your application.

    ViewBag.Title = "Home Page";

        <h5>This si a dumy Paragraph Created to diplay some text on this page.</h5>
                <b>New York:</b>  An Indian diplomat's daughter, who was jailed for a day on suspicion of sending obscene emails to her teacher, has filed a lawsuit against the city of New York and her school authorities seeking USD 1.5 million in damages for her wrongful imprisonment and suspension from school.
 Krittika Biswas, 18, the daughter of Vice-Consul in the Consulate General of India in New York Debashish Biswas, was detained and arrested in February last year on the grounds that she had sent "offensive and sexually threatening" emails to her teachers in Queens's John Browne High School.    

Out Put:

When Loaded

When i click on Like button.

When i am posting the comment on current webpage.

 Finally How it resulted in Facebook.

With this we have achieved the objective of adding Facebook infrastructure using Facebook helper class in MVC Razor application. Code: Click Here
Is it helpful for you? Kindly let me know your comments / Questions.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

Questionfacebook.helper mvc not showing button Pin
Member 120704449-Nov-15 12:54
memberMember 120704449-Nov-15 12:54 
QuestionFacebook.Helper with mvc 5 Pin
ZainNabi19-Aug-14 2:39
memberZainNabi19-Aug-14 2:39 
AnswerRe: Facebook.Helper with mvc 5 Pin
rain_man1-Jan-16 7:22
memberrain_man1-Jan-16 7:22 
QuestionFacebook.Helper with mvc 5 Pin
ZainNabi18-Aug-14 11:12
memberZainNabi18-Aug-14 11:12 
QuestionHello Pin
Member 995916110-Apr-13 21:07
memberMember 995916110-Apr-13 21:07 
Questionhello Pin
Member 995916110-Apr-13 21:06
memberMember 995916110-Apr-13 21:06 
QuestionHttpCompileException Pin
vitalisfan23-Jul-12 22:33
membervitalisfan23-Jul-12 22:33 
QuestionThanks Pin
Patrick Harris23-Jul-12 17:09
memberPatrick Harris23-Jul-12 17:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 23 Jul 2012
Article Copyright 2012 by PratapReddyP
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid