The SharePoint Coffee House
I'd like some SharePoint with my coffee please...

Impersonation Instead of RunWithElevatedPrivileges

Monday, 9 February 2009 13:50 by Michael Mukalian

In my Googling (we all Google to find stuff that we can use, instead of creating from scratch, right?) to find some help with an issue I was having when trying to loop through the UserProfileManager, I came across a really awesome post of Victor Vogelpel's blog that cites some code that Julien Lepine wrote to do some impersonation of the Web Application's ID.  What this code does is basically create an Identity class that runs in the context of the Web Application's ID.  Now, how does this differ with SPSecurity.RunWithElevatedPrivileges?  Well, RunWithElevatedPrivileges is kinda like a "black box" implementation in the context of the built-in "SharePoint\System" identity.  If you utilize the Identity class described above, and you give your Web Application ID the relevant access (in this case, the Manage User Profiles permission in the SSP), you're able to directly know who's doing what, where.  Better than just relying on a "black box" kinda implementation, no?

Check out the code from Victor's article.  It's a little old, but still very relevant.  Cool stuff.

Of special note: On the virtual I was working on at the time I couldn't get anything to work for the above example.  Turns out the issue was related to a fix that was applied when installing the December CU.  Remember to keep your virtual/development environments updated.

- M

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5