Wednesday, March 24, 2010

Impersonating code under execution using RunWithElevatedPrivileges

Whenever code is executed in Console applications, or List event receivers etc, it is executed under the context of the current user. Which means that the privileges the user has will be used to run the code.

If the code is required to be run under a context which does not belong to any windows user (AD user), and needs more privileges than the current user, we can use RunWithElevatedPrivileges and assign a delegate to it as shown below

     //Put your code to be executed using elevated privileges

No comments:

Post a Comment