WindowsImpersonationContext & Impersonate() not found in ASP.Core

前端 未结 2 1337
不思量自难忘°
不思量自难忘° 2020-12-15 09:16

I had the following in a .NET Framework 4.0 assembly:

var newId= new WindowsIdentity(duplicateTokenHandle);
WindowsImpersonationContext newId = ImpersonatedI         


        
2条回答
  •  眼角桃花
    2020-12-15 09:32

    As @Tratcher mentioned you can use the RunImpersonated in .netstandard. The following code sniped is taken from here.

        var user = (WindowsIdentity)context.User.Identity;
    #if NET461
        using (user.Impersonate())
    #else
        WindowsIdentity.RunImpersonated(user.AccessToken, () =>
    #endif
        {
            // var useri = WindowsIdentity.GetCurrent();
        }
    #if !NET461
        );
    #endif
    

提交回复
热议问题