CJ

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

  • Past Post

  • Vistor Locations

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:”

<configuration>
  <system.web>
    <identity impersonate="true" />
  </system.web>
</configuration>

http://msdn.microsoft.com/en-us/magazine/cc163287.aspx

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  .
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3233224&SiteID=1
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3153689&SiteID=1
    http://msdn.microsoft.com/en-us/library/ms494053.aspx
  2. Complete ASP.Net 2.0 impersonation and use an account that has permissions
    http://msdn.microsoft.com/en-us/library/ms998351.aspx
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
%d bloggers like this: