你怎么做模拟在.NET? [英] How do you do Impersonation in .NET?

查看:177
本文介绍了你怎么做模拟在.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的开箱即用的方式来模拟在.NET用户?

Is there a simple out of the box way to impersonate a user in .NET?

到目前为止,我一直使用这个类从code项目了解我所有的模拟要求。

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?

我有一个用户凭据集(用户名,密码,域名),从而重新presents我需要冒充的身份。

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.

  • Michiel van Otegem: WindowsImpersonationContext made easy
  • WindowsIdentity.Impersonate Method (check out the code samples)

基本上,你将充分利用这些类是在.NET Framework中框:

Basically you will be leveraging these classes that are out of the box in the .NET framework:

  • <一个href="http://msdn.microsoft.com/en-us/library/system.security.principal.windowsimpersonationcontext.aspx">WindowsImpersonationContext
  • <一个href="http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx">WindowsIdentity
  • WindowsImpersonationContext
  • WindowsIdentity

在code往往能获得长时间,虽然,这就是为什么你看到很多例子,如一个你引用尽量简化这个过程。

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆