如何PrincipalContext登录到域服务器 [英] How does PrincipalContext login to domain server

查看:1168
本文介绍了如何PrincipalContext登录到域服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的C#code连接到我的域名服务器,并执行它的一些行动。一切正常,我的电脑上,我可以运行所有我的命令就好了。

我的提问是:用于连接到服务器有什么凭据?我认为它使用当前用户的凭据。所以我的真正的问题是将这项工作对普通用户。我是一名管理员,它工作正常我的机器上。

不过,我想知道如果同样的情况也都适用于非管理员?

  PrincipalContext AD =新PrincipalContext(ContextType.Domain,172.18.4.4);

UserPrincipal U =新UserPrincipal(AD);
u.SamAccountName = Environment.UserName;

PrincipalSearcher搜索=新PrincipalSearcher(U);

UserPrincipal结果=(UserPrincipal)search.FindOne();
 

解决方案

如果是code是一个Windows应用程序运行,那么使用的凭据是当前Windows用户的那些,它应该能正常运行的域。如果code是一个ASP.NET网站上运行,那么凭证在该网站上运行的应用程序池的那些。在后一种情况下,你可能需要的应用程序池的身份打:本地系统,网络服务......

在任何previous情况下,可以模拟用户来运行这个code:(看答案)

<一个href="http://stackoverflow.com/questions/5023607/how-to-use-logonuser-properly-to-impersonate-domain-user-from-workgroup-client">How使用的LogonUser正确地从工作组客户模拟域用户

I have the following C# code that connects to my domain server and performs some actions on it. Everything works fine on my computer and I can run all my commands just fine.

My questions is: what credentials are used for the connection to the server? I assume it uses the current users credentials. So my real question is will this work on a normal user. I am an admin and it works fine on my machine.

However I am wondering if the same would hold true for a non admin?

PrincipalContext AD = new PrincipalContext(ContextType.Domain, "172.18.4.4");

UserPrincipal u = new UserPrincipal(AD);
u.SamAccountName = Environment.UserName;

PrincipalSearcher search = new PrincipalSearcher(u);

UserPrincipal result = (UserPrincipal)search.FindOne();

解决方案

If that code is running in a Windows app then the credentials used are the ones of the current Windows user and it should work fine in a domain. If the code is running in an ASP.NET site, then the credentials are the ones of the application pool in which the site is running. In this last case, you might need to play with the Identity of the app pool: LocalSystem, NetworkService...

In any of the previous cases, you can impersonate a user to run this code under: (look at the answer)

How to use LogonUser properly to impersonate domain user from workgroup client

这篇关于如何PrincipalContext登录到域服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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