Pages

Monday, May 7, 2012

Understanding runwithelevatedprivilege in SharePoint 2010

SharePoint is been around for sometime now and there are substantial amount of developer community behind SharePoint. There is also huge push on the enterprise to adopt SharePoint for variety of applications varying from single farm to large scale implementation.Everyone of us would have written code in SharePoint that requires to run with elevated privileges. There are times we tend to miss the fact that run with elevated privilege is a delegate which requires all the SharePoint objects to be created again.  I wanted to write down some of the best practices that one should keep in mind while using run with elevated privilege and which objects should be created again within the elevated context.

Please feel free to add your suggestions in comments.



Primitive ojects
SharePoint Objects
Primitive Objects Viz: String, int, Float etc
 All sharepoint objects Viz: SPSite, SPWeb, SPListItem, SPSList etc
Can be passed from call outside elevated privileges
Cannot pass these objects because of different context where it is created

Always create new SPSite and SPWeb Object

Dispose all the objects once it is used or while leaving the delegate.

Use only when needed and do not use it to bypass security. Instead use impersonation using SPUser Token




No comments:

Post a Comment