Sunday

Code - Impersonation of Current / Logged in User


Following is a snippet of impersonating a currently logged in user in C#. Dead easy!

System.Security.Principal.WindowsImpersonationContext impCtx;
impCtx = ((System.Security.Principal.WindowsIdentity)System.Security.Principal.WindowsIdentity.GetCurrent()).Impersonate();

//write some code here 

impCtx.Undo(); //Don't forget to do this

No comments:

Post a Comment

Your comments are highly appreciated!