How do you do Impersonation in .NET?(您如何在 .NET 中进行模拟?)
问题描述
在 .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 中进行模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您如何在 .NET 中进行模拟?


- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01