Microsoft Knowledge Base Email Alertz

(892866) - Describes a scenario where impersonation does not work when you use some elements of the SharePoint Portal Server object model or the Windows SharePoint Services object model.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 892866 - Last Review: May 23, 2007 - Revision: 1.5

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

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:
http://msdn2.microsoft.com/en-us/library/system.security.principal.windowsidentity.impersonate(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.security.principal.windowsidentity.impersonate(vs.71).aspx)
For more information about the SharePoint Portal Server object model, visit the following Microsoft Web site:
http://www.microsoft.com/technet/prodtechnol/sppt/reskit/c3461881x.mspx (http://www.microsoft.com/technet/prodtechnol/sppt/reskit/c3461881x.mspx)
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:
http://www.microsoft.com/downloads/details.aspx?FamilyID=aa3e7fe5-daee-4d10-980f-789b827967b0&displaylang=en (http://www.microsoft.com/downloads/details.aspx?FamilyID=aa3e7fe5-daee-4d10-980f-789b827967b0&displaylang=en)

APPLIES TO
  • Microsoft Office SharePoint Portal Server 2003
  • Microsoft Windows SharePoint Services 2.0
Keywords: 
kbprogramming kberrmsg kbprb KB892866
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate