What is RevertToSelf ()? - C # .net

I do not understand what RevertToSelf() does in a .net application. Checking the definition of MSDN, he reads the definition as

 The RevertToSelf function terminates the impersonation of a client application. 

So does the current user context in the sysadmin context change, stopping the client context? Calling RevertToSelf () will my code work in sys admin mode?

Update

Well, what happens if I call RevertToSelf () in an ASP.NET application? Let's consider that I do not begin avatars. So, if I call RevertToSelf (), will it return to the application pool id?

+4
source share
4 answers

RevertToSelf terminate any impersonation that you have actively included. You can install the application to impersonate any user account. RevertToSelf does not work unless you use impersonation. Calling RevertToSelf will only cause your code to run as administrator if the application was run as an administrator to start with and was from an application configured to impersonate another account.

+8
source

A few years ago, I wrote a tiny IDisposable -equplementing class called Impersonator to do impersonation / reversal (almost) automatically.

Maybe if you look, it will tell you how and when to use it?

+2
source

It changes in the context of the user who ran the application before impersonation. No need sysadmin. More details here: http://msdn.microsoft.com/en-us/library/aa376391(v=vs.85).aspx

0
source

Assuming that you have certain user credentials (that is, a username and password), you can begin to impersonate and make calls in the Win32 API that are executed in the context of an impersonated user. Thus, you will have access rights to the user whom you impersonate for work until you call RevertToSelf (), in which case you will return to the access rights for the user who originally ran the code.

0
source

Source: https://habr.com/ru/post/1332891/


All Articles