概述
.NET模拟方法
名称空间提供了几个模拟API。首选方法是:System.Security.Principal
>同步假冒:WindowsIdentity.RunImpersonated
<code class="language-csharp"> WindowsIdentity.RunImpersonated(userHandle, () => { /* Impersonated code here */ });</code>
提供了一种用于处理长期运行操作的异步对应物。>
WindowsIdentity.RunImpersonatedAsync
<code class="language-csharp"> await WindowsIdentity.RunImpersonatedAsync(userHandle, async () => { /* Impersonated code here */ });</code>>访问用户帐户:利用logonuser
>LogonUser
重要说明:
<code class="language-csharp">using SimpleImpersonation; var credentials = new UserCredentials(domain, username, password); using SafeAccessTokenHandle userHandle = credentials.LogonUser(LogonType.Interactive);</code>用法需要仔细管理本机手柄和严格的安全惯例。
>远程资源访问:密钥要求
LogonUser
模拟在本地机器上运行。 访问远程资源需要:
>域成员或信任:
以上是我如何在.NET中冒充用户并访问远程资源?的详细内容。更多信息请关注PHP中文网其他相关文章!