Welcome to ASP.NET Guild

Be sure to come back often and tell others. If you have any tips, tricks, examples, please email them to me at chris.williams@techguilds.com and I will post them. Check out our ASP.NET QuickStart and C# QuckStart Libraries. Below is my latest articles.

Monday, May 01, 2017

Introducing the ASP.NET Facebook Login QuickStart

Logging into Facebook is actually quite simple especially if you use our new ASP.NET Facebook Login Quickstart.

If you do not have a copy already email chris.williams@readwatchcreate.com to get instructions on how to access.

Installation

The first step is setting up your database.


  1. Open the database scripts in the QuickStart zip that start with CREATE_TABLE_.  Ensure they table names match your application prefixes for consistency.
  2. Open the database scripts in the QuickStart zip that start with CREATE_PROC_.  Ensure the table names match the tables in the CREATE_TABLE_ scripts in step 1.  
  3. Rename the procs to match your application prefixes for consistency. 
  4. Add the appSetting entries from the web.config in the Quickstart in the Web.Config file for your project. Make sure you change the stored procedure names in the appSettings to match your stored procedure names.
The second step is configure your ASP.NET application to use the plug-in.

  1. Add standard button or link button to page and implement click event.
  2. Call the LoginToFacebook function on this class with a call similar to the following but replace {my_site_name} with your site url.

    You may also want to change the access you desire:

    ASPNET.Authentication.Facebook.FacebookLogin.LoginToFacebook(ConfigurationManager.AppSettings["FacebookAppId"], "http://{my_site_name}/fb.aspx", "offline_access, email, user_likes, friends_likes");
  3. Create a page called fb.aspx and on load add the following code:

    if (Request["code"] != null) Session["AccessToken"] = FacebookLogin.GetAccessToken(ConfigurationManager.AppSettings["FacebookAppId"], ConfigurationManager.AppSettings["FacebookAppSecret"], Request["code"], ConfigurationManager.AppSettings["FacebookReturnUrl"]);
  4. Next you need to add the configuration keys to the web.config in teh appSettings section. These are provided by Facebook when you register your application:

    <add key="FacebookReturnUrl" value="http://{my site}/fb.aspx"/>
    <add key="FacebookAppId" value="{Likely a 15 digit number}"/>
    <add key="FacebookAppSecret" value="{This is a guid with no dashes}"/>
  5. Use the code returned to get the profile info back in JSON then use the helper functions to get each attribute you wish:

    string userProfileJSON = CXFacebook.GetUserProfile(Session["AccessToken"].ToString());
    ///     string id = CXFacebook.GetUserProfileId(userProfileJSON);
    ///     string name = CXFacebook.GetUserProfileName(userProfileJSON);
    ///     string firstName = CXFacebook.GetUserProfileFirstName(userProfileJSON);
    ///     string lastName = CXFacebook.GetUserProfileLastName(userProfileJSON);
    ///     string email = CXFacebook.GetUserProfileEmail(userProfileJSON);
    ///     string birthday = CXFacebook.GetUserProfileBirthday(userProfileJSON);
    ///     string link = CXFacebook.GetUserProfileLink(userProfileJSON);
    ///     string locale = CXFacebook.GetUserProfileLocale(userProfileJSON);
    ///     string quote = CXFacebook.GetUserProfileQuotes(userProfileJSON);
    ///     string userName = CXFacebook.GetUserProfileUserName(userProfileJSON);
    ///     string timeZone = CXFacebook.GetUserProfileTimezone(userProfileJSON);




Are you a .NET Developer or Contractor interested in working with Sitecore or Dynamics CRM?

Apply for our Mentorship Program. If accepted, we will mentor you on Sitecore and provide you with project to help you build your skills and make some money at the same time. If you are interested send your resume with details on why you want to work with Sitecore or Dynamics CRM to: Chris Williams - chris.williams@techguilds.com or Dennis Augustine - dennis.augustine@techguilds.com We look forward to working with you to achieve your goals.