I using ASP.NET Core Identity, with Jmeter app I send multiple requests to my web application for create user and it created multiple users with same email, although my RequireUniqueEmail
is true
services.AddIdentity<User, Role>(identityOptions =>
{
identityOptions.User.RequireUniqueEmail = true;
});
When I send requesets one by one, everything is okay and give me duplicate email error in this code
var result = await _userManager.CreateAsync(userToCreate, userPassword);
But when I send multiple requests with Jmeter, above code can't handle duplicate email and after finish of Jmeter requests, I open SQL server and I see at least 10 records with same email are created.
I searched for this problem and I get this solution Using lock
private static readonly object lockObj = new object();
lock(lockObj)
{
var result = await _userManager.CreateAsync(userToCreate, userPassword);
}
But it gives me error and says "You can't use await in lock statement", and second problem is ASP.NET Core Identity doesn't have Sync method for create. How can I create sync method of create in ASP.NET Core Identity ?