Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi.. Friends, I have the following page in c#.net to get Facebook detail on my website. It is working very fine for me. The only problem is that, if I am login with Facebook and open this page in same browser then it working automatically without my click on the button. My requirement is that when I click on Login with Facebook it work only then oterwise not.

Please tell me how it is possible.

ASP.NET
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html>
<head>
<title>Facebook Get Logged in User Details UserName,Email,Profile Image</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
// Load the SDK Asynchronously
(function(d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));

// Init the SDK upon load
window.fbAsyncInit = function() {
    FB.init({
        appId: '***************', // Your App ID
        channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
        status: true, // check login status
        cookie: true, // enable cookies to allow the server to access the session
        xfbml: true  // parse XFBML
    });

    // listen for and handle auth.statusChange events
    FB.Event.subscribe('auth.statusChange', function(response) {
        if (response.authResponse) {
            // user has auth'd your app and is logged into Facebook
            var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
            FB.api('/me', function(me) {
                document.getElementById('auth-displayname').innerHTML = me.name;
                document.getElementById('Email').innerHTML = me.email;
                document.getElementById('profileImg').src = uid;
                document.getElementById('DOB_User').innerHTML = me.birthday;
                document.getElementById('City').innerHTML = response.authResponse.userID;
                document.getElementById('Gender_User').innerHTML = me.gender;                
            })
            document.getElementById('auth-loggedout').style.display = 'none';
            document.getElementById('auth-loggedin').style.display = 'block';
            
        } else {
            // user has not auth'd your app, or is not logged into Facebook
            document.getElementById('auth-loggedout').style.display = 'block';
            document.getElementById('auth-loggedin').style.display = 'none';
        }
    });
    $("#auth-logoutlink").click(function() { FB.logout(function() { window.location.reload(); }); });
} 
</script>
<h1>
Facebook Login Authentication Example</h1>
<form id="form1" runat="server">
<div id="auth-status">
<div id="auth-loggedout">
<div class="fb-login-button" autologoutlink="false" scope="email,user_birthday">Login with Facebook</div>
</div>
<div id="auth-loggedin" style="display: none">

Name: <span id="auth-displayname"></span>(<a href="#" id="auth-logoutlink">logout</a>)<br />
Email: <span id="Email"></span><br />
Profile Image: <img id="profileImg" /><br />
D.O.B. : <asp:Literal  ID="DOB_User"></asp:Literal><br />
City : <asp:Literal id="City"></asp:Literal>
Gender : <asp:Literal  ID="Gender_User"></asp:Literal>

</div>
<asp:ImageButton ImageUrl="~/images/button/imgFbSignUp.jpg" runat="server"  OnClientClick="login()" />
</div>
</form>
</body>
</html>


Thanks in advance

Parveen Rathi
Posted

1 solution

Hi please check here might be this will helpful for you.

http://onlinewebapplication.com/2012/05/facebook-login-sign-in.html[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900