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 中进行模拟?
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
