© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago
engineertdog

✅ .net8 impersonate

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);
 }
 );
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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ ASP Core Identity .net8
C#CC# / help
3y ago
❔ blazor .net8 vs angular
C#CC# / help
3y ago
Dockerized .NET8 API not accessible.
C#CC# / help
2y ago
.NET8 Serialize class as JSON
C#CC# / help
2y ago