.NET Core的AuthenticationManager的替代方法是什么?

4

我现在正在进行.Net Core项目,我需要接口的AuthenticationManager,也就是IAuthenticationManager

根据微软的文档(此处),这已经过时了。

要获取ApplicationSignInManager,我有以下方法:

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

    }

应用程序登录管理器
 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);
    }
}

由于使用了CreatePerOwinContext,在Mvc项目中这是有效的。

    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

在此输入图片描述

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

同时在这里了解到,在 .Net Core 中这个 CreateOwinContext 已经过时了(参考链接),但我不知道如何调用 ApplicationSignInManager 的 create 方法。

1个回答

9

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

这种访问方式已经过时了一段时间。现在,在 HttpContext 上直接有扩展方法来完成此操作:

现在,您只需要访问当前的HttpContext,就可以直接调用身份验证操作,而无需使用AuthenticationManager间接方法。
至于与OWIN相关的事情,请注意ASP.NET Core不使用OWIN,而是创建了一个全新的系统。该系统基于OWIN,因此您可以找到熟悉的东西,但仍然有根本上的区别。因此,您需要适应新的身份验证系统

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接