c# - Identity UpdateAsync 丢失 IdentityResult.Failed

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

我已经为我在 ASP.NET MVC 5.1 应用程序中使用的 ASP.NET Identity 编写了自定义 UserStore。一切都按预期工作,我对 ASP.NET 的这个新功能(身份)感到非常满意......

问题是,自从我尝试从 UpdateAsync 方法返回错误以来,我认为已经快 2 天了,而且不知何故,我似乎无法返回任何内容。

LE:我正在使用 ASP.NET Identity Core 2.0.0-beta1

这是我的几行代码:

public Task UpdateAsync(IdentityUser user)
{
    AdminUserEntity userEntity = new AdminUserEntity();
    userEntity.IsNew = false;
    userEntity.Id = user.UserModel.Id;
    userEntity.UserCompleteName = user.UserModel.UserCompleteName;
    userEntity.IsDisabled = user.UserModel.IsDisabled;

    if (!String.IsNullOrEmpty(user.UserModel.PasswordHash))
        userEntity.PasswordHash = user.UserModel.PasswordHash;

    if (user.Claims != null && user.Claims.Count > 0)
    {
        foreach (Claim claim in user.Claims)
        {
            AdminUserClaimEntity claimEntity = userEntity.AdminUserClaims.AddNew();
            claimEntity.AdminUserUniqueId = user.UserModel.UniqueId;
            claimEntity.ClaimType = claim.Type;
            claimEntity.ClaimValue = claim.Value;
        }
    }

    try
    {
        byte[] timestamp = Convert.FromBase64String(user.UserModel.Timestamp);
        AdminUserEntityManagement.UpdateCompleteAdminUserEntity(userEntity, timestamp);
    }
    catch (Exception exception)
    {
        List<string> errors = new List<string>() {exception.Message};
        return Task.FromResult<IdentityResult>(IdentityResult.Failed(errors.ToArray()));
    }

    return Task.FromResult<object>(null);
}

尽管出现异常并且正在执行 catch block ,但以下行始终返回成功:

IdentityResult result = await UserManager.UpdateAsync(identityUser);

有人可以告诉我我错过了什么吗?

最佳答案

我假设这个 UpdateAsync 在你的 ApplicationUserManager 类中,签名不应该是

public override Task<IdentityResult> UpdateAsync 

如果您尝试更改 UserManager 的 UpdateAsync 方法的工作方式。

关于c# - Identity UpdateAsync 丢失 IdentityResult.Failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22174079/

相关文章:

html - 如何使内部元素忽略样式

asp.net-mvc - SignalR 无法从外部程序集找到集线器

c# - 通过基类c#实现的接口(interface)调用类的方法

c# - 防止调用下一个事件处理程序

c# - EnumerateFiles 以避免缓存

c# - 如何在网站项目的页面上使用其他C#源文件?

asp.net - 使用自定义成员资格提供程序时,在 ASP.NET 中推荐的用户特定持久变量存储方法是什么?

c# - MVC : The view found at '~/.../Index.cshtml' was not created

c# - 使用 CaSTLe 在自定义成员提供程序中注入(inject)属性

php - 如何从 php 页面返回响应