Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Logic behind UserManager.Get{Property}Async methods

$
0
0

When looking through scaffolded Identity code, I see things like this pretty frequently:

var user = await _userManager.GetUserAsync(User); // gets user from ClaimsPrincipal

// ... later on...
var email = await _userManager.GetEmailAsync(user);

If we already have the IdentityUser, why do we later go back to the _userManager and make a whole new database call? We already have the IdentityUser.Email property in our method.

One section of scaffolded code where this happens is in the Identity/Pages/Account/Manage/Email.cshtml.cs file. The IdentityUser is fetched using the ClaimsPrincipal, and then both the user ID and email address are then retrieved from the database instead of the IdentityUser instance. This adds two extra async calls that, at face value, are entirely unnecessary because the data is already present in that context.


Viewing all articles
Browse latest Browse all 4737

Trending Articles



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