c# - .Net Core 中 AuthenticationManager 的替代方法是什么

标签 c# asp.net-mvc asp.net-core owin owin-middleware

我正在处理 .Net Core 项目,现在我需要 AuthenticationManager 接口(interface) IAuthenticationManager

根据微软this已经过时了。

要获取 ApplicationSignInManager,我有这个方法

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

    }

ApplicationSignInManager

 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);

enter image description here

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

在这里还了解到这个CreateOwinContext在.Net core中已经过时了here但不知道如何调用 ApplicationSignInManager 的创建方法?

最佳答案

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

此访问权限已被弃用很长一段时间了。现在有extensions methods直接在用于此目的的 HttpContext 上:

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

至于 OWIN 相关的东西,请注意 ASP.NET Core 不使用 OWIN 而是创建了一个全新的系统。那个是基于 OWIN 的,所以你可以找到熟悉的东西,但仍然有根本的不同。所以你需要习惯the new authentication system .

关于c# - .Net Core 中 AuthenticationManager 的替代方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58128901/

相关文章:

asp.net-core - ASP.NET Core 自定义脚手架 - Visual Studio 2019

c# - 为什么此 C# 代码无法编译?

jquery - 使用 ASP.NET MVC3 将表单数据从 jqueryUI 对话框传递到 Controller

c# - 根据公钥指数/模数进行 WinRT RSA 加密

asp.net-mvc - 断言 MVC Controller 操作的返回类型

asp.net-mvc - 操作链接按钮

c# - 外键引用对象返回 null

asp.net - 使用 IdentityServer 的 Asp Core 客户端全局注销

c# - ListBlobs 不列出已删除的 blob

c# - 查询 XML 的 Entity Framework