AuthenticationManager引用丢失

7 asp.net asp.net-mvc entity-framework asp.net-identity

跟进这个问题,缺少方法的参考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);
}
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决它吗?

Hor*_*Net 9

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

private IAuthenticationManager AuthenticationManager
{
  get
  {
    return HttpContext.GetOwinContext().Authentication;
  }
}
Run Code Online (Sandbox Code Playgroud)

有了它,您应该能够调用SignOutSignIn方法.


Suh*_*shi -1

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