【发布时间】:2016-05-26 17:26:46
【问题描述】:
我在我的应用程序中创建了一个名为 ProfileContoller 的控制器。
在这个控制器中,我需要创建一个ApplicationUserManager 的实例,但是我不知道如何创建它的一个新实例。我试过下面的代码:
private ApplicationUserManager _userManager = Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
但我收到了这个错误:
名称
Current在当前上下文中不存在
我的第一个问题是我该怎么做?我将访问这行代码:
return View(await _userManager.FindByNameAsync(username));
我也使用UnityContainer。我的第二个问题是:我是否也可以注册与接口IUser 或IUserStore 关联的ApplicationUserManager1。
更新:
后来我发现有这样的东西:
private UserManager<ApplicationUser> _userManager = UserManager<ApplicationUserManager>();
它给我这个错误:
不可调用的成员
UserManager<TUser>不能像方法一样使用。
有了这个额外的“用户管理器”,我就看不到树木了。那么您能再解释一下所有“用户管理器”的含义以及它们的用途吗?
注意:
1我不知道这两者之间的区别,所以如果你愿意,你能解释一下吗?子>
【问题讨论】:
-
你有正确的 using 语句吗? stackoverflow.com/questions/24001245/…
-
关于
cannot be used like a method的嗯——你错过了new关键字吗? -- 看起来你确实在尝试调用一个像方法一样的类型......
标签: c# asp.net entity-framework unity-container user-management