0

在重定向到 facebook 以获取代码令牌并且当 facebook 重定向回我时,我的应用程序停止响应,应该调用的操作永远不会启动。问题出在哪里?

我的路线

routes.MapRoute(
  "Enter facebook return",
  "enter/facebook/return",
   new { controller = "Users", action = "FacebookReturn" } //callback action, which not called -> problem
);

 routes.MapRoute(
    "Enter facebook",
    "enter/facebook",
    new { controller = "Users", action = "Facebook" }
 );

和我的控制器

    public ActionResult Facebook()
    {
        OAuth2 facebook = new OAuth2(
            ConfigurationManager.AppSettings["oauth_facebook_id"].ToString(), 
            ConfigurationManager.AppSettings["oauth_facebook_secret"].ToString(), 
            ConfigurationManager.AppSettings["oauth_facebook_authorize"].ToString(), 
            ConfigurationManager.AppSettings["oauth_facebook_access"].ToString(), 
            ConfigurationManager.AppSettings["oauth_facebook_return"].ToString()
        );

        Session["enter_facebook"] = facebook; // save data to session

        Dictionary<string, string> p = new Dictionary<string, string> { { "scope", "email" } };

        string redirectURL = facebook.GetAuthCode(p); //redirect url

        //redirect url looks like https://www.facebook.com/dialog/oauth?client_id=111111111&response_type=code&redirect_uri=http%3A%2F%localhost.loc%2Fenter%2Ffacebook%2Freturn&scope=email

        return Redirect(redirectURL);
    }

    public ActionResult FacebookReturn(string code)
    {
        if (!string.IsNullOrEmpty(code))
        {
            //after returning to us
            OAuth2 facebook = (OAuth2)Session["enter_facebook"];
            facebook.Code = code; //getting code
            Dictionary<string, string> p = new Dictionary<string, string> { { "client_secret", ConfigurationManager.AppSettings["oauth_facebook_secret"].ToString() } }; //additional params

            OAuth2Token token = facebook.GetAccessToken(p, OAuth2.AccessTokenType.Dictionary); //getting marker access
            string access_token = token.dictionary_token["access_token"];
            if (!string.IsNullOrEmpty(access_token))
            {
                string user_data = OAuth2UserData.GetFacebookUserData(access_token); //getting data about user
                string a = "";
            }

        }

        return View("Enter");
    }

我的 livehhttpheader

GET https://www.facebook.com/dialog/oauth?client_id=111111111&response_type=code&redirect_uri=http%3A%2F%localhost.loc%2Fenter%2Ffacebook%2Freturn&scope=email

Host: www.facebook.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://localhost.loc/enter
Connection: keep-alive

所以在最后我看到当我点击“用facebook登录”时:

1. https://www.facebook.com/dialog/oauth?client_id=111111111&response_type=code&redirect_uri=http%3A%2F%localhost.loc%2Fenter%2Ffacebook%2Freturn&scope=email

2. http://localhost.loc/enter/facebook/return?code=2222222222

3.我的应用程序停在这里,FacebookReturn(string code) 从未调用过,无法在 p.2 中获取地址(登录 firefox 作为加载并且永远不会结束),但是如果只是调用 p.2 而没有重定向一切都很好

所以问题是:为什么在从 facebook 重定向到我的站点后,操作从不调用,并且似乎在应用程序池中出现了一些问题

4

0 回答 0