Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当我尝试使用Facebook或Google登录时,GetExternalLoginInfoAsync始终返回null_C#_Asp.net Mvc_Asp.net Mvc 5_Owin - Fatal编程技术网

C# 当我尝试使用Facebook或Google登录时,GetExternalLoginInfoAsync始终返回null

C# 当我尝试使用Facebook或Google登录时,GetExternalLoginInfoAsync始终返回null,c#,asp.net-mvc,asp.net-mvc-5,owin,C#,Asp.net Mvc,Asp.net Mvc 5,Owin,我对OWIN的身份验证有问题。当我尝试使用Facebook或Google登录时,我总是从getexternallogininfosync()接收空值 但是有一个神秘的例子。。当我打开小提琴手。我使用此方法获得正确的数据。 我不明白原因 var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); 提前谢谢 我通过添加此代码解决了我的问题 context.RequestContext.HttpContext.Re

我对OWIN的身份验证有问题。当我尝试使用Facebook或Google登录时,我总是从
getexternallogininfosync()
接收空值

但是有一个神秘的例子。。当我打开小提琴手。我使用此方法获得正确的数据。

我不明白原因

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

提前谢谢

我通过添加此代码解决了我的问题

context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
在课堂上:

    private class ChallengeResult : HttpUnauthorizedResult
    {
        public ChallengeResult(string provider, string redirectUri)
            : this(provider, redirectUri, null)
        {
        }

        public ChallengeResult(string provider, string redirectUri, string userId)
        {
            LoginProvider = provider;
            RedirectUri = redirectUri;
            UserId = userId;
        }

        public string LoginProvider { get; set; }
        public string RedirectUri { get; set; }
        public string UserId { get; set; }

        public override void ExecuteResult(ControllerContext context)
        {
            // this line fixed the problem with returing null
            context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;

            var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
            if (UserId != null)
            {
                properties.Dictionary[XsrfKey] = UserId;
            }
            context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
        }
    }
它修复了我返回
NULL
的问题


注意:使用twitter授权登录时不要使用fiddler。您将收到错误。

似乎同样的问题。您能确认此行为是否在ExternalLoginCallback方法内吗?@Bilal我有此问题,是的,它在该方法内。请参考此问题: