Scroll To Top
Reader Level:

Impersonation in Sharepoint

By Destin joy on Aug 13, 2010
There are many situations while we work with share point that we need to impersonate a user with higher permission or with Admin privileged user. This will help to do the same.

While working with share point there are several situations that we need to do impersonation. For example, while you work with site creation programmatically and you don't want to give full privilege to the user who does the same. In such Scenarios this small code be helpful to you.

Before starting you have to use the below two namespaces

using System.Security.Permissions;

using System.Security.Principal;

Add the below two functions





Please call the function UseAppPoolIdentity() where ever you want to impersonate the user with admin rights. When you finished with admin privileged operation just call t he second function  ReturnToImpersonatingCurrentUser().