✅ .net8 impersonate

c#
bool returnValue = LogonUser("", "", "",
    LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT,
    out safeAccessTokenHandle);

WindowsIdentity.RunImpersonated(
 safeAccessTokenHandle,
 // User action
 () => {
   // Check the identity.
   Console.WriteLine("During impersonation: " + WindowsIdentity.GetCurrent().Name);
 }
 );


This logs the current user and not the identity that's impersonated. I need to be able to execute certain tasks as users. Is this just not reasonable with net8?

Nevermind, the current identity lied. That was code taken from the MS docs website. If I do an action, then it does use that context. Misleading that the current identity isn't correct.
Was this page helpful?