C#-等待AuthenticationManager.GetExternalLoginInfoAsync()返回null
作者:互联网
当我第一次尝试使用外部提供程序登录时,此返回null,然后我再次按提供程序,一切都很好.我认为Cookie有点问题,因为删除所有Cookie并重试时会发生错误.
如果我删除所有Session和TempData,一切正常,那为什么呢?
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(new NotImplementedException("Error ExternalLoginCallback"));
TempData["_Error"] = "El incio de sesión con redes sociales no está disponible en este moemento, intente con su usuario y clave";
return RedirectToAction("Login");
}
}
解决方法:
我必须创建一个过滤器以下
public class FilterBase : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!filterContext.IsChildAction && !filterContext.HttpContext.Request.IsAjaxRequest())
{
/*
* MICROSOFT BUG
* https://stackoverflow.com/questions/20737578/asp-net-sessionid-owin-cookies-do-not-send-to-browser/21234614#21234614
* https://katanaproject.codeplex.com/workitem/197
*/
filterContext.HttpContext.Session["Workaround"] = 0;
}
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
}
}
标签:owin,asp-net-mvc-5,c 来源: https://codeday.me/bug/20191122/2057355.html