Impersonation in SharePoint 2007

In SharePoint 2003 there was no easy way to use impersonation. In SharePoint 2007 there is a nice and easy build in way to use impersonation:

SPSite site = new SPSite("SiteCollection_Url");
SPWeb web = site.OpenWeb();
SPUser user = web.AllUsers["User_Name"];

SPUserToken token = user.UserToken;
SPSite impersonatedSiteCollection = new SPSite("SiteCollection_Url", token);

You can also check whether an SPSite object is using impersonation:

SPSite siteCollection = SPControl.GetContextSite(HttpContext.Current);
bool impersonating = siteCollection.Impersonating;

Print | posted @ Thursday, November 02, 2006 8:14 PM

Comments on this entry:

No comments posted yet.

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 6 and 4 and type the answer here: