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
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:
For example, you may experience this symptom in the following scenario:
- Impersonation code is called from a Web part or from console code that runs under an anonymous user.
- Impersonation code is called to make sure that an administrator account is used in this context.
- The call to the SPWeb.Roles collection in this scenario fails.
- The following code is run:
SPSite siteCollection = new SPSite("http://localhost");
SPWeb web2 = siteCollection.OpenWeb();
SPRole adminRole = web2.Roles["Administrator"]; - The access to the web2.Roles collection fails.
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.
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:
APPLIES TO
- Microsoft Office SharePoint Portal Server 2003
- Microsoft Windows SharePoint Services 2.0
| 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