控制器动作从不调用

时间:2013-08-23 15:18:46

标签: c# asp.net-mvc facebook oauth-2.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(字符串代码)从未调用,无法在p.2中获取地址(登录firefox作为加载并永不结束),但是如果只是调用p .2没有重定向一切都很好

所以问题是:为什么在从facebook重定向到我的网站后,动作永远不会出现问题,而且似乎在应用程序池中出现了一些问题

0 个答案:

没有答案