【问题标题】:AuthenticationManager references missing缺少 AuthenticationManager 引用
【发布时间】:2014-03-02 06:38:43
【问题描述】:

跟进this 问题,缺少对SignOut()SignIn() 方法的引用:

private async Task SignInAsync(User user, bool isPersistent)
{
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
    var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
    AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}

有人知道怎么解决吗?

【问题讨论】:

    标签: asp.net asp.net-mvc entity-framework asp.net-identity


    【解决方案1】:

    这些方法应该在 Microsoft.Owin.Security 命名空间中定义。你能检查一下你的Microsoft.Owin dll是否在项目中被正确引用了

    【讨论】:

      【解决方案2】:

      您是如何定义您的 AuthenticationManager 属性的?通常它应该如下所示:

      private IAuthenticationManager AuthenticationManager
      {
        get
        {
          return HttpContext.GetOwinContext().Authentication;
        }
      }
      

      这样你就可以调用 SignOutSignIn 方法了。

      【讨论】:

        【解决方案3】:

        GetOwinContext() 是存在于 Microsoft.Owin.Host.SystemWeb.dll 中的扩展方法。

        您必须添加 Microsoft.Owin.Host.SystemWeb NuGet 包。

        它是 System.Web 命名空间的一部分。因此,请确保在 using 部分中包含 System.Web。

        【讨论】:

          【解决方案4】:

          如果您在控制器外部调用,则应按以下方式定义 AuthenticationManager。

              private IAuthenticationManager AuthenticationManager
              {
                  get
                  {
                      return HttpContext.Current.GetOwinContext().Authentication;
                  }
              }
          

          【讨论】:

            【解决方案5】:

            您可能包含了System.Net 而不是Microsoft.Owin.Security。两者都有AuthenticationManager 类的定义。

            【讨论】:

              猜你喜欢
              • 2018-08-14
              • 1970-01-01
              • 1970-01-01
              • 2019-10-15
              • 2011-09-14
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多