locked
EVENT RECEIVER: how to properly impersonate user RRS feed

  • Question

  • I have a custom list event receiver (LIST A updating) that will also update data in other custom lists. However, I do not want to give direct permissions to these other lists. Users shall only have controlled access via code in the event receiver. My best bet is to impersonate the user when the event receiver executes. Would you have an example how to do this properly? thanks very much.
    Iko
    • Moved by Clayton Cobb Thursday, January 6, 2011 4:50 AM Programming question (From:SharePoint 2010 - Using SharePoint Designer, Infopath, and other customization)
    Thursday, January 6, 2011 4:14 AM

Answers

  • Hi

    Have you tried using SPSecurity.RunWithElevatedPrevileges

    Write your code inside this block where you want to impersonate.

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        //you code here
    });
    
    The code inside the block runs with highest previleges, which is your previleges when you deploy. Try it and let me know if that works.
    • Marked as answer by Wayne Fan Tuesday, January 11, 2011 7:54 AM
    Thursday, January 6, 2011 5:03 AM

All replies

  • Iko, that's a development question, not SPD/InfoPath.  Moving...
    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    Thursday, January 6, 2011 4:48 AM
  • Hi

    Have you tried using SPSecurity.RunWithElevatedPrevileges

    Write your code inside this block where you want to impersonate.

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        //you code here
    });
    
    The code inside the block runs with highest previleges, which is your previleges when you deploy. Try it and let me know if that works.
    • Marked as answer by Wayne Fan Tuesday, January 11, 2011 7:54 AM
    Thursday, January 6, 2011 5:03 AM
  • Indeed. Sorry, my bad...
    Iko
    Thursday, January 6, 2011 5:24 AM
  • Will try that. thanks much.
    Iko
    Thursday, January 6, 2011 5:25 AM