.Net Core 中 AuthenticationManager 的替代品是什么

TAH*_*URI 1 c# asp.net-mvc owin owin-middleware asp.net-core

我现在在 .Net Core 项目上工作,我需要 AuthenticationManager 接口 IAuthenticationManager

据微软称,已经过时了。

要获得 ApplicationSignInManager 我有这个方法

      private ApplicationSignInManager getSignInManager(ApplicationUserManager manager, IAuthenticationManager auth)
    {
        return new ApplicationSignInManager(manager, auth);

    }
Run Code Online (Sandbox Code Playgroud)

应用登录管理器

 public class ApplicationSignInManager : SignInManager<ApplicationUser, string>
{
    public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
        : base(userManager, authenticationManager)
    {
    }
    public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
    {
        return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
    }
}
Run Code Online (Sandbox Code Playgroud)

由于使用调用 CreatePerOwinContext,这在 Mvc 项目中确实有效

    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

但是如何在 .Net Core 中激活这个类?

也曾在这里了解到,这CreateOwinContext是.NET中的核心obsolote这里,但无法弄清楚如何调用创建的方法ApplicationSignInManager

pok*_*oke 5

AuthenticationManager是通过HttpContext.Authentication属性执行身份验证相关操作的实用程序。例如,您调用HttpContext.Authentication.SignInAsync(…)登录用户。

此访问权限已被弃用一段时间。现在有直接用于此目的的扩展方法HttpContext

所以现在您只需要访问当前HttpContext,您就可以直接调用身份验证操作,而无需AuthenticationManager间接。

至于 OWIN 相关的东西,注意 ASP.NET Core 没有使用 OWIN 而是创建了一个全新的系统。那个是基于 OWIN 的,所以你可以找到熟悉的东西,但仍然有根本的不同。因此,您需要习惯新的身份验证系统