The new ASP.NET MVC 5 Project-template generates a prepared AccountController , which includes the basic implementation of UserManager and base stores ( IUserStore , IRoleStore , etc.).
This tutorial shows how to implement a custom UserStore to store user data in a user data source: http://www.asp.net/identity/overview/extensibility/implementing-a-custom-mysql-aspnet-identity-storage-provider
However, I executed my own UserStore and found out the following:
During the login process, the UserManager.FindAsync(UserName, Password) method is called inside the AccountController :
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { **var user = await UserManager.FindAsync(model.UserName, model.Password);**
The FindAsync method calls the basic UserStore methods in the following order: FindByNameAsync β GetPasswordHashAsync β FindByIdAsync .
My question is: why are both called FindByNameAsync and FindByIdAsync methods? This results in 2 database queries, which affects performance.
source share