Impersonation does not work when you use the SharePoint Portal Server object model or the Windows SharePoint Services object model to impersonate an authenticated user (892866)



The information in this article applies to:

  • Microsoft Office SharePoint Portal Server 2003
  • Microsoft Windows SharePoint Services

SYMPTOMS

You write code that uses the Microsoft Office SharePoint Portal Server object model or the Microsoft Windows SharePoint Services object model to try to impersonate an authenticated user in one or both of the following contexts:
  • In the context of a Web Part
  • In the context of a program that runs under an anonymous user or of a program that runs under a non-authenticated user
However, impersonation does not work with some SharePoint Portal Server object model calls or with some Windows SharePoint Services object model calls. You may receive an error message that is similar to the following:
Access is Denied
For example, you may experience this symptom in the following scenario:
  1. Impersonation code is called from a Web part or from console code that runs under an anonymous user.
  2. Impersonation code is called to make sure that an administrator account is used in this context.
  3. The call to the SPWeb.Roles collection in this scenario fails.
  4. The following code is run:
    SPSite siteCollection = new SPSite("http://localhost");
    SPWeb web2 = siteCollection.OpenWeb();
    SPRole adminRole = web2.Roles["Administrator"];
  5. The access to the web2.Roles collection fails.

CAUSE

Impersonation is not currently supported in the SharePoint Portal Server object model or in the Windows SharePoint Services object model. This functionality is being investigated for future versions of the object models.

MORE INFORMATION

For more information about code that you can use to impersonate a different Microsoft Windows user, visit the following Microsoft Web site: For more information about the SharePoint Portal Server object model, visit the following Microsoft Web site: For more information about the Windows SharePoint Services object model, see the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK). To obtain the SharePoint Products and Technologies 2003 SDK, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:10/12/2006
Keywords:kbProgramming kberrmsg kbprb KB892866 kbAudITPRO kbAudDeveloper