Reasons to elevate fall into two categories:
- Your code needs to perform operations in SharePoint for which the current user does not have permissions. This should always be done while working with SharePoint security, not as a "just in case" measure which indicates you need to understand your security situation better.
- Your code needs to access external resources (server file system, database, file share, etc) to which the application pool identity has access but the current user does not.
For the former, you're much better off using SPSite impersonation. The latter is the only reason I ever use RWEP.
To clarify, RWEP does not spawn a new thread. Instead it uses Win32 APIs to revert the current thread's identity back to the process identity (turning off impersonation) to run the elevated code, then switch impersonation back on to resume work on behalf of the current user. This has several implications:
- RWEP does nothing if the thread isn't impersonated, so it is useless in timer jobs, Visual Studio workflows, console applications, and code run via stsadm (feature receivers).
- Access to SharePoint, assuming you create a new SPSite in your CodeToRunElevated, will be performed with the rights of the application pool (SHAREPOINT\system). This account will have full access to the current web application, but should not have farm-level permissions to do things like modify SPFarm properties or make changes to the SSP.
- Using identity-aware objects (like SPSite and its children) across the execution boundaries of your CodeToRunElevated has the potential to cause some really funky behavior and race conditions. For all intents and purposes, consider this unsupported.
And as Alex said, children of an SPSite inherit their permissions from the SPSite, which in turn has its permissions set when it is created. So SPContext.Current.Site will still behave with the permissions of the current user even if you reference it within your CodeToRunElevated. Instead, you would need to create and consume a new SPSite within the elevated block.
To summarize: RWEP to impersonate the App Pool outside of SharePoint, SPSite impersonation to impersonate the App Pool inside of SharePoint.