Custom Properties on Identity lost in asynchronous call/thread

Custom Properties on Identity lost in asynchronous call/thread

Old forum URL:

ctkach posted on Friday, January 15, 2010


I've searched through the forum's but couldn't find an answer to how others have designed a custom identity class that allows for custom properties to be referenced within a child/worker thread.

My current situation is this.  We have built a custom identity class that contains additional data on the user who has authenticated to the system (read from a database and stored in encapsulated fields on the custom identity object in normal OO fashion).

However, when we call a method asynchronously using a delegate and the BeginInvoke method it appears that all custom properties in the identity are lost/not transferred/copied into the new worker thread as evidenced by the missing data when we access the identity through the Csla.ApplicationContext.User.Identity property from the worker thread (however, the custom identity does in fact exist and the standard properties are populated).  Is there a special technique to storing this custom data that must be obeyed in order for it to be copied into the worker thread with the rest of the identity?

And if it matters, this is for an ASP.NET application of which we have followed the standard method of retrieving the custom principal from session during the Application_AcquireRequestState method in global.asax.

Any ideas on how to properly design the custom Identity to handle this situation would be appreciated!

- Chris

JonnyBee replied on Saturday, January 16, 2010


For ASP.NET applications CSLA stores/gets the current principal from the HttpContext.Current.User.
This property is returned as an IPrincipal and you must explicitly cast it to your type to access custom properties.

If your async thread is unable to access the HttpContext you must transfer the custom identity to your child/worker thread and reset the custom identity for that thread.

If possible - I would recommend you to use the async methods on DataPortal (or use as example). The asyn call transfer both;:
* Thread Custom identity
* Thread CurrentCulture and CurrentUICulture
* GlobalContext and ClientContext in Csla (stored in a named slot on Thread)
to the worker thread and resets the values.

Copyright (c) Marimer LLC