在这个上下文中开始了第二个操作,即使 Dbcontext 被声明为 trainsent

问题描述 投票:0回答:0

这个错误并不总是产生一些东西,当数据库在服务器上时如果数据库在本地机器上没有问题 我在sql数据库和mysql数据库中找到了它 DbContext 注册为 ServiceLifetime.Transient 但问题仍然出现在服务器上的数据库

当我尝试在

 user.RoleNames = await userManager.GetRolesAsync(user);

中为用户获取角色时出现问题
 protected async System.Threading.Tasks.Task Load()
        {
            var securityGetUserByIdResult = await Security.GetUserById($"{Id}");
            user = securityGetUserByIdResult;

            var securityGetRolesResult = await Security.GetRoles();
            roles = securityGetRolesResult;
        }

然后我调用 GetUserById

public async Task<ApplicationUser> GetUserById(string id)
        {
            var user = await userManager.FindByIdAsync(id);
            
            if (user != null)
            {
                context.Entry(user).Reload();
                user.RoleNames = await userManager.GetRolesAsync(user);
            }

            return await Task.FromResult(user);
        }

我尝试了多种解决方案,比如 semaphoreSlim 没有解决问题

asp.net entity-framework blazor web-hosting identity
© www.soinside.com 2019 - 2024. All rights reserved.