RunWithElevatedPrivileges:-
SPSecurity.RunWithElevatedPrivileges() is used to execute some code that has to be run under some higher privileges.
The RWEP method enables us to supply a delegate that runs a subset of code in the context of an account with higher privileges than the current user. Basically the code executed inside this method has "System Account" privileges in addition to the current user privileges or in a better way - we can tell that this method runs under the Application Pool identity, which has site collection administrator privileges on all site collections hosted by that application pool. In other words, whenever we use SPSecurity.RunWithElevatedPrivileges(), it will execute the code under the context of Application Pool identity.
If we are defining an Event Receiver, then we can use properties argument to get the URL.
Additional Blogs:-
SPSecurity.RunWithElevatedPrivileges() is used to execute some code that has to be run under some higher privileges.
The RWEP method enables us to supply a delegate that runs a subset of code in the context of an account with higher privileges than the current user. Basically the code executed inside this method has "System Account" privileges in addition to the current user privileges or in a better way - we can tell that this method runs under the Application Pool identity, which has site collection administrator privileges on all site collections hosted by that application pool. In other words, whenever we use SPSecurity.RunWithElevatedPrivileges(), it will execute the code under the context of Application Pool identity.
If we are defining an Event Receiver, then we can use properties argument to get the URL.
SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(properties.Web.Url)) { using (SPWeb web = site.OpenWeb()) { // ... TO DO TASK } } });
Additional Blogs:-
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.