ABP FindByNameOrEmailAsync 方法 return 空值

ABP FindByNameOrEmailAsync method return null value

当我从邮递员调用 FindByNameOrEmailAsync 方法时,它 returns 用户。但是一旦我通过 UI 发送值,方法 returns 为空。 虽然该值绑定到 usernameOrEmailAddress 变量并进入该方法,但它 returns null.

有人可以帮助我吗?

   <input type="email" id="emailInput" class="form-control" maxlength="255" placeholder="Enter your email" required />
   <button id="requestResetEmail" class="btn btn-primary btn-block btn-flat">Request password reset</button>


      abp.ui.setBusy(
        $('#LoginArea'),
        abp.ajax({
            url: abp.appPath + 'Account/ForgotPassword',
            type: 'POST',
            data: JSON.stringify({
                usernameOrEmailAddress: $('#emailInput').val(),
                returnUrl: window.location.hash
            })
        })

  public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
    {
        if (ModelState.IsValid)
        {
            var user = await 
          _userManager.FindByNameOrEmailAsync(model.UsernameOrEmailAddress);

        if (user == null || !(await _userManager.IsEmailConfirmedAsync(user.Id)))
            {                 
                return View("ForgotPasswordConfirmation");
            }
        }
        else
        {
          return View(model);
        }
   }

您需要设置正确的租户。

如果用户名或电子邮件地址在租户之间是唯一的,请注入 IUnitOfWorkManager 并执行:

using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
{
    var user = await _userManager.FindByNameOrEmailAsync(model.UsernameOrEmailAddress);
    // ...
}

如果_unitOfWorkManager.Currentnull,把上面的代码换成:

using (var uow = _unitOfWorkManager.Begin())
{
    // Above code goes here

    uow.Complete();
}