+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to execute EventHub code under full permissions?

How to execute EventHub code under full permissions?

3 posts, 0 answered
  1. Bryan Johnson
    Bryan Johnson avatar
    2 posts
    Registered:
    27 Jul 2009
    06 Nov 2014
    Link to this post

    I'm new to Sitefinity.  I've built out an EventHub handler to react to items submitted to the Forms module that creates new items in a content type within a module built with Module Builder using the CreateDataItem method of the DynamicModuleManager class.  This works OK if I submit the form data while logged in as an administrator.  However, if I submit form data as an anonymous user, I get a System.UnauthorizedAccessException when my code hits the SaveChanges method of the DynamicModuleManager class.

     How can I ensure that my EventHub-triggered code will run with full permissions, even if it is triggered by an anonymous user's action?

  2. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    09 Dec 2016
    11 Nov 2014
    Link to this post
    Hi Bryan,

    Can you please add the following line after you get the dynamic module manager (and before you call SaveChanges()):

    DynamicModuleManager dynamicManager = DynamicModuleManager.GetManager();
     
    dynamicManager.Provider.SuppressSecurityChecks = true;

    When the SuppressSecurityChecks property is set to true the permissions check of the provider should be skipped and you will be able to execute the code with anonymous identity.

    Regards,
    Sabrie Nedzhip
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Bryan Johnson
    Bryan Johnson avatar
    2 posts
    Registered:
    27 Jul 2009
    11 Nov 2014 in reply to Sabrie Nedzhip
    Link to this post
    Thank you, Sabrie.  That suggestion solved my problem.
3 posts, 0 answered