Hi,
I have created a sample Asp.NET project to see how basic identity works? I found out after calling createAsync(), the user data will be stored in database like below:
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
<span style="color:#FF4000"> var result = await UserManager.CreateAsync(user, model.Password);</span>
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
But in module zero , I found that after calling createAsync, there is a SaveChangesAsync function. Why do I need to call this? And when does the data actually write to the DB? It seems that after the CreateAsync function, the data is not stored in DB right away.
Your help is quite appreciated!
<cite>hikalkan: </cite> Can you try this one:
public async Task CreateUserWithoutAuthorization(UserInput input) { var testUser = new User { CellPhone = input.CellPhone, EmailAddress = input.EmailAddress, UserName = input.UserName }; (await _userManager.CreateAsync(testUser)).CheckErrors(); }
I changed void to Task. The only thing I can see is that for now.
Thanks! But can you please brief me in about why the return type matters? Your help is really appreciated!! :D
Hi,
I am a newbie here and are still struggling about the comprehensive concepts about ABP. I tried to add a register page, writing some code about the registration service like this in .Application layer:
async void IUserService.CreateUserWithoutAuthorization(UserInput input)
{
var testUser = new User
{
CellPhone = input.CellPhone,
EmailAddress = input.EmailAddress,
UserName = input.UserName
};
(await _userManager.CreateAsync(testUser)).CheckErrors();
}
Something happens when calling CreateAsync function. IDE tells me : Cannot access disposed object: UserManagerProxy. I have no idea why this object is disposed at the moment.
StackTrace are as follows:
at Microsoft.AspNet.Identity.UserManager`2.ThrowIfDisposed()
at Microsoft.AspNet.Identity.UserManager`2.<CreateAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Abp.Authorization.Users.AbpUserManager`3.<CreateAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
Then I tried to remove await, but I found the test user is not saved in AppUsers Table. But it successfully returns an Id. I am wondering where the testUser is stored? Please find the code and the connectionString down below:
_userManager.CreateAsync(preInsert);
var user = _userManager.FindByNameAsync(testUser.UserName);
<add name="Default" connectionString="Server=localhost; Database=AbpTestDb; Trusted_Connection=True;" providerName="System.Data.SqlClient" />
Can any one help me with this :D ? Or tell me where I should dig in? Or give me some good articles about how userManager really works in Asp.NET identity? I am totally lost...
Thanks very much!