I had the following in a .NET Framework 4.0 assembly:
var newId= new WindowsIdentity(duplicateTokenHandle);
WindowsImpersonationContext newId = ImpersonatedIdentity.Impersonate();
I'm porting it to ASP.Core, but WindowsImpersonationContext
and WindowsIdentity.Impersonate()
aren't found.
I've tried adding the following:
System.Security.Claims 4.3.0
System.Security.Principal 4.3.0
System.Security.Principal.Windows 4.4.0
How do I perform impersonation in ASP.Core?
Update
It looks like it's not supported in .NET Core or .NET Standard - is there a work-around or do I have to resign to targeting the framework?
Necromancing.
Like this:
Usage:
As @Tratcher mentioned you can use the
RunImpersonated
in .netstandard. The following code sniped is taken from here.