当我第一次尝试使用外部提供者登录时返回 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
* http://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)
{
}
}
关于c# - 等待 AuthenticationManager.GetExternalLoginInfoAsync() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21654277/