More in this section
Forums / Sitefinity SDK / Errors with Managers when Multi-Threading

Errors with Managers when Multi-Threading

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Duneel
    Duneel avatar
    166 posts
    08 Dec 2010
    22 Jun 2011
    Link to this post

    I'm using a different thread to perform a time consuming task in custom widget. So in that task, I need to use Managers to ready/write content from/to sitefinity. Now the problem is since that logic runs on a different thread I can execute the manager and I'm receiving "Missing current principal" exception. How should I resolve this?

    Is there a way to access these managers under a specific user? How to achieve this?

  2. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    01 Nov 2016
    28 Jun 2011
    Link to this post
    Hello Duneel,

    One way to do this is to turn off security checks. This is done at the provider level. It is important to turn it on after you complete your operation. So i suggest you use try - finally block.
    manager.Provider.SuppressSecurityChecks = true;
    ///Your code///
    manager.Provider.SuppressSecurityChecks = false;
    I also suggest that you manually Dispose() your manager at the end of your background task - since this causes disposing of the ORM resources - database connections.

    We also have a static method that you can use to run code with elevated privileges.
    This actually simulates the HttpContext as it was called with a system user in admin role. Your code should be put in a delegate that this method calls. It returns the previous state of the HttpContext once the code is finished. Again disposing your managers is important to free db resources.

    Nikolay Datchev
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  3. Brandon
    Brandon avatar
    0 posts
    28 Sep 2015
    30 Nov 2016
    Link to this post

    Thanks, SystemManager.RunWithElevatedPrivilege was the key to our multi-threading implementation using Parallel.ForEach.

    DataProviderBase.RaiseAfterEvents accesses SystemManager.CurrentHttpContext and that is null in a multi-threaded situation unless running your code under SystemManager.RunWithElevatedPrivilege.

3 posts, 0 answered