问题描述
在 .NET 中是否有一种开箱即用的简单方式来模拟用户?
Is there a simple out of the box way to impersonate a user in .NET?
到目前为止,我一直在使用 代码项目中的这个类我的模拟要求.
So far I've been using this class from code project for all my impersonation requirements.
使用 .NET Framework 是否有更好的方法?
Is there a better way to do it by using .NET Framework?
我有一个用户凭据集(用户名、密码、域名),它代表我需要模拟的身份.
I have a user credential set, (username, password, domain name) which represents the identity I need to impersonate.
推荐答案
这里有一些很好的 .NET 模拟概念概述.
Here is some good overview of .NET impersonation concepts.
- Michielvan Otegem:WindowsImpersonationContext 变得简单
- WindowsIdentity.Impersonate 方法(查看代码示例)
基本上,您将利用 .NET 框架中开箱即用的这些类:
Basically you will be leveraging these classes that are out of the box in the .NET framework:
- WindowsImpersonationContext
- WindowsIdentity
代码通常会变得很长,这就是为什么您会看到许多示例,例如您引用的示例,它们试图简化流程.
The code can often get lengthy though and that is why you see many examples like the one you reference that try to simplify the process.
这篇关于您如何在 .NET 中进行模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!