c# - 等待 AuthenticationManager.GetExternalLoginInfoAsync() 返回 null

标签 c# asp.net-mvc-5 owin

当我第一次尝试使用外部提供者登录时返回 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/

相关文章:

MySQL DB : Nullable bool in database column, 枚举或两个 bool 列,哪一个更高效?

c# - 转换 Web API 以使用自托管

azure - OWIN静态文件安全

c# - 有什么方法可以配置 owin startup.cs 在全局 asax 应用程序启动之前运行?

c# - 将简单注入(inject)器与 SignalR 结合使用

c# - Monogame:无法将资源作为非内容文件加载

mysql - 如何通过 Entity Framework 从数据库中获取单值

c# - 当前上下文 ASP.NET MVC5 中不存在名称 'Model'

c# - 如何在不破坏现有客户端的情况下使用 C# 重新实现旧的 DCOM 服务器?

c# - Windows Azure 上的 System.Speech 错误