The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

  • Advertisements

Not everything works using the SPSecurity.RunWithElevatedPrivileges

Posted by Clayton James on May 15, 2008

Web parts and application pages run under the context of the of the windows account.

“When the code behind a Web Part or a custom application page executes in response to a user request, the code does not execute under the worker process identity of the hosting Web application. Instead, WSS uses impersonation to switch the Windows security context over to another Windows account. In fact, if you look inside the web.config file for a WSS Web application, you will see the following entry:”

    <identity impersonate="true" />


So if you are creating a web part that performs some type of operation…say updating user profiles using the UserProfileManager class, then you will receive permission errors because the windows account doesn’t have the required permissions. Even if you try to run the code using SPSecurity.RunWithElevatedPrivileges you will receive these permission errors.
Note: It usually works in development because you are logged in as an administrator.

So you have a couple of options:

  1. You will need to use the User Profile web service as there are some issues with the Object Model and elevation when using the  .
  2. Complete ASP.Net 2.0 impersonation and use an account that has permissions

One Response to “Not everything works using the SPSecurity.RunWithElevatedPrivileges”

  1. spanish desserts cookies

    Not everything works using the SPSecurity.RunWithElevatedPrivileges « CJ

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: