【问题标题】:How to mange user from class in asp.net core(identity 3.0.0 Rc1)如何在 asp.net core 中管理用户(身份 3.0.0 Rc1)
【发布时间】:2016-04-15 11:47:24
【问题描述】:

我刚刚启动了asp.net core,现在我想在一个类中管理用户 在 mvc 5 中,就像这段代码一样简单:

  var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
        var currentUser = manager.FindById(HttpContext.Current.User.Identity.GetUserId());

但我不知道如何管理 identity 3.0.0 Rc1 中的用户。 希望大家能给我推荐一个好方法

【问题讨论】:

  • 你想要实现什么?

标签: asp.net .net asp.net-identity asp.net-core-mvc asp.net-identity-3


【解决方案1】:

@regnauld 问了个好问题;)但是回答一般情况...

您可以在UserManager 类中找到大多数“用户管理”操作。


其他方式:

首先,请阅读Introduction to Identity v3

然后在 Visual Studio 中创建新的 MVC Core 项目并选择 Authentication: Individual User Accounts 选项...


...这为您提供了带有“准备使用”AccountControllerManageController 的默认 MVC 项目,您可以在那里找到很好的示例如何在 Identity 3 中管理用户。

【讨论】:

  • 我认为问题在于以更通用的方式使用 Usermanager。在 MVC 核心中,用户管理器默认注入到控制器中。您将如何从控制器外部访问它们?
猜你喜欢
  • 1970-01-01
  • 2016-07-25
  • 2021-06-23
  • 1970-01-01
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多