I asked a question extremely similar to this recently and I am waiting until I solve this variation to my question before marking an answer.
I have an ASP.Net app and I need to track an Editor and Author field for every entity. You can see the full question here: MVC tracking fields such as Author and Editor (Created By and Modified By)
My variation now is that I am going to use Azure AD. Therefore I have no ApplicationUser
or DbSet <ApplicationUser>
to query. However, I need to be able to save a users SID in the Author
field of the entity and then later, when that entity is displayed on the page, pull the corresponding display name.
Could someone point me in the right direction of how I need to be storing the field, and how best practice recommends to them get the users display name for every entity. Do I need to query Azure AD Every time I display a user?
I would store the SID in a simple string field. You can look up the SID length definition and simply use that as a restriction.
You can think about adding the Display Name while saving in an additional column, but I would not recommend it. The display name might change and depending on your data and data protection laws, it might also prove problematic.
When you display the user, resolve the display name after retrieving the entity, and build a in memory cache for mapping SIDs to the display names so you don't need to call AAD every time.
https://docs.microsoft.com/en-us/dotnet/framework/performance/caching-in-net-framework-applications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With