Search code examples
c#.netimpersonationadvapi32

What is RevertToSelf()? - C#.net


I don't understand what RevertToSelf() does in a .net application. Checking MSDN definition it reads the definition as

The RevertToSelf function terminates the impersonation of a client application.

So does the current user context changes to a sysadmin context by stopping client's context? By calling RevertToSelf() will my code run on sys admin mode?

Update

Okay so what happens if I call RevertToSelf() in an ASP.NET application? Let us consider I dont start any impersonation. So if I call RevertToSelf() will it revert to the application pool identity?


Solution

  • RevertToSelf will terminate any impersonation that you have actively enabled. You may set an application to impersonate any user account. RevertToSelf has no effect unless you're using impersonation. Calling RevertToSelf will only get your code to run as an administrator, if the application is was up to run as an administrator to begin with, and was from within the application configured to impersonate another account.