【问题标题】:Error-using the generic type AspNet.Identity.usermanager<Tuser> requires 1 type of argument? [duplicate]错误使用泛型类型 AspNet.Identity.usermanager<Tuser> 需要 1 种类型的参数? [复制]
【发布时间】:2014-12-10 18:13:08
【问题描述】:

我在尝试使用 UserManager.CreateAsync(user, reg.password) 代码时收到此错误。请帮忙。 还有一件事我安装了包 aspnet.identity.core 包。但我不能参考它。当我尝试使用 Using 来引用它时,我找不到包。

        if (ModelState.IsValid)
        {
            var user = new ApplicationUser() { UserName = reg.username };
            var result = await UserManager.CreateAsync(user, reg.password);
              if (result.Succeeded)
            {
                await SignInAsync(user, isPersistent: false);
                return RedirectToAction("Index", "Account");
            }
            else
            {
                AddErrors(result);
            }

【问题讨论】:

  • 谢谢。你得到的确切错误是什么?
  • 这篇文章的标题

标签: c# asp.net .net asp.net-mvc-4 asp.net-identity


【解决方案1】:

这里的问题是您的代码试图直接在UserManager&lt;TUser&gt; 类上调用CreateAsync(),而.CreateAsync() 需要在UserManager&lt;TUser&gt;实例 上调用。

在 Identity 包提供的样板代码中,这是通过在 AccountController 中定义的属性完成的:

public ApplicationUserManager UserManager
{
    get
    {
        return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
    }
    private set
    {
        _userManager = value;
    }
}

你的控制器中有这样的属性吗?

【讨论】:

    猜你喜欢
    • 2021-10-24
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多