【发布时间】:2020-07-02 12:36:17
【问题描述】:
我正在将我的 ASP.net MVC 项目迁移到核心版本。我有一个带有方法的扩展类,它通过用户 ID(Guid)返回用户名。
public static class IdentityHelpers
{
public static MvcHtmlString GetUserName(this HtmlHelper html, string id)
{
var manager = HttpContext.Current
.GetOwinContext().GetUserManager<AppUserManager>();
return new MvcHtmlString(manager.FindByIdAsync(id).Result.UserName);
}
}
当我将其重写为 .NET Core 时,我不知道如何在此处获取用户管理器实例。通常我会通过 DI 注入它,但我不知道该怎么做,因为我使用的是扩展方法,所以我无法注入它。
如何在静态类中获取UserManager?
【问题讨论】:
标签: c# asp.net-core .net-core asp.net-identity