8

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?

1 Answer 1

4
+50

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://learn.microsoft.com/en-us/dotnet/framework/performance/caching-in-net-framework-applications

5
  • I agree with this. I have always stored the SID (or object ID) when referencing a user from Active Directory.
    – Dan Wilson
    Mar 30, 2018 at 16:37
  • This is what I am doing now. It proves problematic when attempting to display a large list of entities and the persons that edited that entity. An in memory cache seems like it would resolve some of that, but I was hoping for something even better performance wise.
    – S. Walker
    Mar 31, 2018 at 12:31
  • How many users does your AAD have? How many users will use the application you are trying to optimize? How many are in a result? Depending on all that, there might be an even better solution. But the cache should be a huge improvement already. Another evolution would be to only send the SIDs to the client, and then asynchronously get the display names of the visible items (or just page the whole list). Combine that with a cache and you should be good. If you have many users and fear the memory cache would grow too large, you could look into something like redis cache. But I would try it first.
    – Alex AIT
    Mar 31, 2018 at 15:38
  • @AlexAIT, This is the solution I expected to get. I was hoping for something a little cleaner all together. For example, when connecting to a local AD, getting a user's display name only takes a few lines of code whereas the use of the Graph API requires a different conceptual model of implementation because communication is via HTTP. Thank you for your help, Caching is the take away and we will work to implement it.
    – S. Walker
    Apr 2, 2018 at 12:09
  • Ok I was not getting that from your question. If you consider your bounty solved, I would appreciate it. Glad I could help a bit either way.
    – Alex AIT
    Apr 2, 2018 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.