Concurrent exception in ASP .NET Core WEB API with single database in Postman

  Kiến thức lập trình

Using VS 2022 – .Net Core API project uses .Net 8.0

I have created the API in above environment. Used IdentityAPI and created wrapper class for the UserManager API
Using DependencyManager, AddScoped() DbContext which was derived from the IdentityDbContext.

AddScoped<ExpIdentityDbContext>()
.AddDbContext<ExpIdentityDbContext>(options =>
{
  options.UseSqlServer(configuration.GetConnectionString("ExpUsers"));
  options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTrackingWithIdentityResolution);
});

In-fact i have added same database to another DbContext for the other tables which are not part of the Identity tables. For checking WebAPI methods, i have activated swagger also.

I have created 2 controllers to creating new user, list the user, change the password and reset the password. In AuthController, i have placed the methods for changing password and reset it.

with this configuration, i could login and create and list users.. But the changepassword and resetpassword is not working as expected. changepassword is throwing “Optimistic concurrency failure, object has been modified.”
and resetpassword : throws “Invalid token”.. in my API i have created a method to generate token using the

userManager.GeneratePasswordResetTokenAsync

and i used the generated token to reset the password. But both in vain..
i checked several articles and searched for solutions in the stack overflow and tried them. but none solved the issue.

any help on this would be appreciated

tried various examples in stack overflow and followed MSDN articles also.

LEAVE A COMMENT