Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:50:39+00:00 2026-05-31T23:50:39+00:00

Just getting started building an app using the v6 of the facebook c# sdk

  • 0

Just getting started building an app using the v6 of the facebook c# sdk and stuck on the login process for facebook. I have the following code in my page:

    string client_id = ConfigurationManager.AppSettings["APIKey"].ToString();
    string client_secret = ConfigurationManager.AppSettings["Secret"].ToString();
    string redirect_uri = ConfigurationManager.AppSettings["Url"].ToString() + "default2.aspx";

    FacebookClient objClient = new FacebookClient();

    var fbLoginUrl = objClient.GetLoginUrl(new { client_id = client_id, 
                                                 client_secret = client_secret, 
                                                 redirect_uri = redirect_uri, 
                                                 response_type = "code",
                                                 display = "popup",
                                                 scope = "manage_pages,publish_stream,read_stream", 
                                                 state = "" });
    //msg.Text = fbLoginUrl.ToString();
    Response.Redirect(fbLoginUrl.ToString());

When I go to the page, the redirect to log in never happens. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:50:40+00:00Added an answer on May 31, 2026 at 11:50 pm

    With MVC 3 (look at the published example), i make a view where the login starts. The controller is :

            public ActionResult Logon()
        {
            _fb = new FacebookClient();
    
            var csrfToken = Guid.NewGuid().ToString();
            Session["fb_csrf_token"] = csrfToken;
    
            var state = Convert.ToBase64String(Encoding.UTF8.GetBytes(_fb.SerializeJson(new { returnUrl = returnUrl, csrf = csrfToken })));
    
            var fbLoginUrl = _fb.GetLoginUrl(
                new
                {
                    client_id = AppId,
                    client_secret = Appsecret,
                    redirect_uri = RedirectUri,
                    response_type = "code",
                    scope = Scope,
                    state = state
                });
            return Redirect(fbLoginUrl.AbsoluteUri);
        }
    

    where returnUrl is the connected view area in my app (/home/fbhome) and RedirectUri is the view (loginresult) which will deals the second step :

            public ActionResult Loginresult(string code, string state)
        {
            if (string.IsNullOrWhiteSpace(code) || string.IsNullOrWhiteSpace(state))
                return RedirectToAction("Index", "Home");
    
            // first validate the csrf token
            _fb = new FacebookClient();
            dynamic decodedState;
            try
            {
                decodedState = _fb.DeserializeJson(Encoding.UTF8.GetString(Convert.FromBase64String(state)), null);
                var exepectedCsrfToken = Session["fb_csrf_token"] as string;
                // make the fb_csrf_token invalid
                Session["fb_csrf_token"] = null;
    
                if (!(decodedState is IDictionary<string, object>) || !decodedState.ContainsKey("csrf") || string.IsNullOrWhiteSpace(exepectedCsrfToken) || exepectedCsrfToken != decodedState.csrf)
                {
                    return RedirectToAction("Index", "Home");
                }
            }
            catch
            {
                // log exception
                return RedirectToAction("Index", "Home");
            }
    
            try
            {
                dynamic result = _fb.Post("oauth/access_token",
                                          new
                                          {
                                              client_id = AppId,
                                              client_secret = Appsecret,
                                              redirect_uri = RedirectUri,
                                              code = code
                                          });
    
                Session["fb_access_token"] = result.access_token;
    
                if (result.ContainsKey("expires"))
                    Session["fb_expires_in"] = DateTime.Now.AddSeconds(result.expires);
    
                if (decodedState.ContainsKey("returnUrl"))
                {
                    if (Url.IsLocalUrl(decodedState.returnUrl))
                        return Redirect(decodedState.returnUrl);
                    return Redirect(decodedState.returnUrl + "/notlocal");
                }
    
                return RedirectToAction("Index", "Home");
            }
            catch
            {
                // log exception
                return RedirectToAction("Index", "Home");
            }
        }
    

    So, as far as i understand, the user enter the site (/home/index) then click on a link to connect (/home/loggon), facebook answer to (/home/loginresult) and the user is redirected to /home/fbhome

    Hope this helped

    Sorry for my english !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just getting started learning rails. I am building my first app using
Just getting started using MVC in ASP.NET, I'm going to have it so users
I am just getting started with flex and am using the SDK (not Flex
I'm building a site, and have just started getting into developing the backend. The
Just getting started with Obj-C and iOS programming. I have some code that loads
I am just getting started with Silverlight and have recently added a Silverlight project
I have a webapp that I'm building, and have just started with SQLite. I
just getting started with Rails, I would like to consume a webservice (using ActiveResource)
Note: I'm just getting started with Jenkins plugin development and have never used maven
I am just getting started using NAnt. I was working from a tutorial, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.