SharePoint Short #20 Instead of explicitly wrapping code in a RunWithElevatedPrivileges block, it’s better to first check if the user has sufficient privileges and only elevate when they don’t. Instead of: SPSecurity.RunWithElevatedPrivileges(() => { // elevated code... }); Do this: public void RunWithElevatedPrivileges(SPWeb web, SPSecurity.CodeToRunElevated elevatedCode) { if (web.CurrentUser.IsSiteAdmin) { elevatedCode(); return; } SPSecurity.RunWithElevatedPrivileges(elevatedCode); } […]
↧