Is there a way to detect if my code is running inside SPSecurity.RunWithElevatedPrivileges?
class Foo
{
public static void Bar()
{
if (CODE_RUNS_ELEVATED)
{
Debug.WriteLine("You are elevated");
}
else
{
Debug.WriteLine("You are not elevated");
}
}
}
SPSecurity.RunWithElevatedPrivileges(() => Foo.Bar()); // Prints: You are elevated
Foo.Bar(); // Prints: You are not elevated
My problem is how to resolve CODE_RUNS_ELEVATED
.
UPDATE: Some observations I did so far:
- Thread.CurrentPrincipal: logged on identity
- WindowsIdentity: application pool identity
- HttpContext.Current.User.Identity: logged on identity
So the only thing, which changes when doing the 'RWEP' is the WindowsIdentity.GetCurrent() from NT AUTHORITY\IUSR (with claims authentication) or from the logged on user (with windows integrated authentication) to the application pool identity.