Showing posts with label RunWithElevatedPrivileges. Show all posts
Showing posts with label RunWithElevatedPrivileges. Show all posts

Tuesday 13 March 2012

When should I use SPSecurity.RunWithElevatedPrivileges?

It is very importent to understand why and when to use SPSecurity.RunwithElevatedPrivilages.When we want to retrive or update the data where a normal user don't have permission,there we use this code segment. How this exactly works is like SPSecurity.RunWithElevatedPrivileges runs current process under application pool identity and it allows users to add/update item in list,library or site.


Example 


SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(web.Site.ID))
    {


      // site will be based on the rights for the system account

    }

});


For more details click here

Pages

Followers