Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 831
NLV Avatar asked Dec 21 '10 12:12

NLV


2 Answers

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.

like image 111
David Hedlund Avatar answered Oct 02 '22 10:10

David Hedlund


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?

like image 27
Uwe Keim Avatar answered Oct 02 '22 10:10

Uwe Keim