Question

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?

Était-ce utile?

La solution

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

Autres conseils

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...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top