2017-10-02 39 views
0

で見つかっていない私は、.NET Framework 4.0のアセンブリに次のようにしていた:がWindowsImpersonationContext&偽装()ASP.Core

var newId= new WindowsIdentity(duplicateTokenHandle); 
WindowsImpersonationContext newId = ImpersonatedIdentity.Impersonate(); 

私はASP.Coreにそれを移植するんだけど、WindowsImpersonationContextWindowsIdentity.Impersonate()ではありません見つかりました。

私は、次を追加しようとしました:

  • System.Security.Claims 4.3.0
  • System.Security.Principal 4.3.0
  • System.Security.Principal.Windows 4.4.0

私はASP.Coreで偽装を実行するにはどうすればよいですか?

更新

それは.NETのコアまたは.NET標準でサポートされていないように見えます - 回避策があるか、私はフレームワークをターゲットに辞任しなければなりませんか?

+1

RunImpersonatedという新しいメソッドがあります。 – Tratcher

答えて

0

@Tratcherが述べたように、RunImpersonatedは.netstandardで使用できます。以下のコードはhereから抜粋したものです。

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