Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

Some years ago I've written a tiny IDisposable-implementing class called Impersonator to do the impersonation/revertion (nearly) automatically.

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

It changes to context of user that ran the application before impersonation. It is not necessary sysadmin. Read more here: http://msdn.microsoft.com/en-us/library/aa376391(v=vs.85).aspx

Assuming you have a certain user's credentials (ie. username and password), you can begin impersonation and make calls to the Win32 API that execute in the context of the impersonated user. So you will have the the access rights of the user you are impersonating, UNTIL you call RevertToSelf(), in which case you will revert to the access rights of the user who originally launched the code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top