Reputation: 22964
I need to store an ID against a user that will be used in EVERY action that is carried out on my web application. I had hoped to use a customized authorization ActionFilterAttribute
(on an entire controller) to populate the ViewData
with this additional info, but it turns out that a whole STACK of stuff runs before these ActionFilterAttributes
do e.g. ModelBinding, Controller construction
I thought perhaps there may be a way to extend the HttpContext.User.Identity
to store additional data but have no idea even where to start.
Any ideas?
Upvotes: 2
Views: 3600
Reputation: 22964
SOLUTION
Looking around in more detail on StackOverflow I came across this solution that does EXACTLY what I want and in a super clean and proper way (HINT: It uses the userData
property of the FormsAuthenticationCookie
- https://stackoverflow.com/a/10524305/175893
Upvotes: 1
Reputation: 70369
One option is to have a global (static) ConcurrentDictionary
and store any additional information regarding the identity/user there - use whatever is convenient as a key... since this dictionary is thread-safe and implemented mostly lock-free it provides excellent performance... this way you don't need to mess around with any ASP.NET-specific stuff...
Upvotes: 0