知道为什么Facebook提供商在下面的代码中失败了吗?

时间:2016-07-17 08:35:33

标签: facebook asp.net-web-api oauth-2.0

我使用Facebook为我的WebAPi服务实施OAUTH登录,我使用以下方法获取令牌:

private static async Task<ExternalLoginData> FromToken(string provider, string accessToken)
        {
            if (string.IsNullOrEmpty(provider))
                return null;

            provider = provider.Trim().ToLower();

            string verifyTokenEndPoint = "", verifyAppEndpoint = "";
            HttpClient client = new HttpClient();

            if (provider == ProviderConstants.Facebook)
            {
                verifyTokenEndPoint = $"https://graph.facebook.com/me?access_token={accessToken}";
                verifyAppEndpoint = $"https://graph.facebook.com/app?access_token={accessToken}";
            }
            else
            {
                return null;
            }

            Uri uri = new Uri(verifyTokenEndPoint); 
            HttpResponseMessage response = await client.GetAsync(uri); <-- exception thrown here

            if (response.IsSuccessStatusCode)
            {
                //not relevant
            }

            //not relevant
        }

在任何配置上,本地开发服务器上都不会抛出异常。但它在具有以下错误的实时服务器上失败。

知道为什么吗?

Failed when generating token
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 1.1.1.1:443
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at FishingApp.Controllers.AccountController.<FromToken>d__32.MoveNext() in E:\TeamCity\buildAgent\work\22810208a40a1b66\src\FishingApp\Controllers\AccountController.cs:line 1033
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at FishingApp.Controllers.AccountController.<LoginExternalToken>d__30.MoveNext() in E:\TeamCity\buildAgent\work\22810208a40a1b66\src\FishingApp\Controllers\AccountController.cs:line 865

其他信息:看起来我无法连接到网址,因为我收到此错误:Unable to connect to the remote server

1 个答案:

答案 0 :(得分:7)

自从过去5天以来我遇到了同样的问题,2天前看到了你的问题,但那段时间我没有得到答案。

解决方案: 可能是您使用 Smarterasp.net 作为您的托管服务提供商。 他们在&#34;安全标签&#34;中引入了一个额外的设置。 ,他们拒绝任何内部连接默认情况下发送到graph.facebook.com。但如果你需要这个,你必须&#34;启用&#34;这个设置。

Smarterasp Snapshot

祝你好运