Facebook Login Integration with your application using asp.net in c#

Facebook login integration with your application:



default.aspx(source code):

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="s1.admin.CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <script type="text/javascript">
    

</script>
 
    <title></title>
</head>
<body>

    <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnLogin" runat="server" Text="Login with FaceBook" OnClick="Login" />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            <asp:Panel ID="pnlFaceBookUser" runat="server" Visible="false">

                <table>
                    <tr>
                        <td rowspan="5" valign="top">
                            <asp:Image ID="ProfileImage" runat="server" Width="50" Height="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>ID:<asp:Label ID="lblId" runat="server" Text=""></asp:Label></td>
                    </tr>
                    <tr>
                        <td>UserName:<asp:Label ID="lblUserName" runat="server" Text=""></asp:Label></td>
                    </tr>
                    <tr>
                        <td>Name:<asp:Label ID="lblName" runat="server" Text=""></asp:Label></td>
                    </tr>
                    <tr>
                        <td>Email:<asp:Label ID="lblEmail" runat="server" Text=""></asp:Label></td>
                    </tr>
                </table>
            </asp:Panel>
        </div>
    </form>
</body>
</html>


default.aspx.cs(codebehind page):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPSnippets.FaceBookAPI;
using System.Web.Script.Serialization;

namespace s1.admin
{
    public partial class CS : System.Web.UI.Page
    {
        protected void Login(object sender, EventArgs e)
        {
            FaceBookConnect.Authorize("user_photos,email", Request.Url.AbsoluteUri.Split('?')[0]);
         
        }

        protected void Page_Load(object sender, EventArgs e)
        {
          
            FaceBookConnect.API_Key = "556139377812012";
            FaceBookConnect.API_Secret = "e1e10044c57b488ebce8efa29a454480";
          //get api key and api secret in facebook
            {
                if (Request.QueryString["error"] == "access_denied")
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
                    return;
                }

                string code = Request.QueryString["code"];
                if (!string.IsNullOrEmpty(code))
                {

                    string data = FaceBookConnect.Fetch(code, "me");
                    FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
                    faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture", faceBookUser.Id);
                    pnlFaceBookUser.Visible = true;
                    lblId.Text = faceBookUser.Id;
                    lblUserName.Text = faceBookUser.UserName;
                    lblName.Text = faceBookUser.Name;
                    lblEmail.Text = faceBookUser.Email;
                    ProfileImage.ImageUrl = faceBookUser.PictureUrl;
                    Session["da"] = data.ToString();
                   // btnLogin.Enabled = false;
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            FaceBookConnect.Logout(Request.QueryString["code"]);
          
          
        }
}
    public class FaceBookUser
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string UserName { get; set; }
        public string PictureUrl { get; set; }
        public string Email { get; set; }
    }
}

Get api key and api secret in facebook


First Register in:  https://developers.facebook.com/



 https://developers.facebook.com/ 

following instruction (or) create

Website:

Site URL:http://localhost:54808/Default.aspxCanvas URL:http://localhost:54808/Default.aspx/Page Tab URL:http://localhost:54808/Default.aspx