Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

UserManager Issues

$
0
0

I follows the link below to create a project testing 

https://gooroo.io/GoorooTHINK/Article/17333/Custom-user-roles-and-rolebased-authorization-in-ASPNET-core/32835#.Wx60sYPwaM9

I put some testing code in Home Controller Index See the code below; First I comment out Delete user lines to create a new user with two roles, it works, I see the data in these tables, Then I un-comment the Delete user lines and comment out the Create a new User lines, I expect I can get these tow roles' names assigned to this user, but the result count is zero. and get error {Failed : ConcurrencyFailure} and "Optimistic concurrency failure, object has been modified. on line   var resulta = await _userManager.DeleteAsync(user); I do not know what I miss? anyone can help me on this? Thanks?

<div>public async Task<IActionResult> Index()</div> <div>        {</div> <div>            var user = new ApplicationUser { UserName = "JohnDoe3", Email = "johndoe3@xyz.com" };</div> <div>            //Create a new user and add the user to these two roles, no problem</div> <div>    var result = await _userManager.CreateAsync(user);</div> <div>            await _userManager.AddToRoleAsync(user, "Admin");</div> <div>            await _userManager.AddToRoleAsync(user, "User");</div> <div> </div> <div>            </div> <div>    //Delete the user</div> <div>            var RolesForUser = await _userManager.GetRolesAsync(user); the count = 0, so no roles associated with this user</div> <div>            var result1 = await _userManager.RemoveFromRoleAsync(user, "Admin");</div> <div>            var result2 = await _userManager.RemoveFromRoleAsync(user, "User");</div><div>            var resulta = await _userManager.DeleteAsync(user);//get error {Failed : ConcurrencyFailure} and "Optimistic concurrency failure, object has been modified.</div> <div> </div> <div>            return View();</div><div>}</div>


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>