我正在将现有的.NETClass项目迁移到Core。在这里,我们试图从owincontext获取当前的用户管理器,您能否帮助我们如何在.NET core中实现这一目标?
我尝试使用HttpContext,但他们不再有OWINContext或GetUserManager((
private CustomStore _myStore;
private MyContext _dbContext;
private AppUserManager _userManager;
private AppRoleManager _roleManager;
public CustomManager(HttpContext ctx)
{
_dbContext = ctx
.GetOwinContext().Get<MyContext>();
_userManager = ctx
.GetOwinContext().GetUserManager<AppUserManager>();
_roleManager = ctx
.GetOwinContext().Get<AppRoleManager>();
}
对于另一种选择,您可以实现自己的扩展以获得类似UserManager
public static class HttpContextExtension
{
public static UserManager<TUser> GetUserManager<TUser>(this HttpContext context) where TUser: class
{
return context.RequestServices.GetRequiredService<UserManager<TUser>>();
}
}