English 中文(简体)
C# 使用不同的用户证书访问活动目录
原标题:C# accessing active directory with different user credentials

我们刚刚为用户提供了一个新的用户创建应用程序。 然而,这些用户需要有能力通过应用程序创建用户,即使他们自己没有创建用户的权限。

在 C# 中, 您如何冒充另一个用户来拥有此功能 。 此应用程序主要使用 < code> System. stirty services

代码片断 :

DirectoryEntry dEntry = new DirectoryEntry("LDAP://OU=");
DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
//filter just user objects
dSearcher.SearchScope = SearchScope.Subtree;
dSearcher.Filter = "(&(objectClass=user)(mail=" + excel_Holding_Table.Rows[i]["EmailAddress"].ToString() + "))";
dSearcher.PageSize = 1000;
sResults = dSearcher.FindAll();
问题回答

使用 < a href=" "http://msdn.microsoft.com/en-us/library/wh2h7eed.aspx" rel = "no follow" > DistricentyEntry 构建器,使用用户名、密码和认证Type参数 。

除此以外, IntientyEntry BirtySearcher Searcher SearchResult Collection 类型是 IDisposable - 您需要用 使用 语句进行处置。

使用目录 Entry 构造器( string, String, String, String, String, String, String, 验证类型), 该构造器使用用户名和密码而不是冒名顶替 。

DirectoryEntry directoryEntry = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/Root", @"domainusername", "password", AuthenticationTypes.Secure | AuthenticationTypes.Sealing); 

https://stackoverflow.com/ questions/9620566/impermanate-not-work-for-directoryservices><参考

您可以使用特许证书连接AD或冒充特权用户,如其他答复所示。

但这涉及安全问题,因为这意味着你的用户可以将这些特权证书用于其他非授权目的。

更安全的解决办法是创建在服务账户下运行的网络服务,并有适当的自动识别许可。 用户可以使用 Windows 认证对网络服务进行认证,而网络服务将代表用户创建用户。 它可以使用授权来限制用户可以做什么(例如,仅在自己的部门创建用户 ) 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签