MVC Active Directory 成员资格
我正在尝试使用活动目录成员身份而不是 SQL,但在线可用的文档非常有限。我已经成功地将我的应用程序连接到域控制器,没有任何问题,但是当您使用“Context.User.Identity.Name”时,它会出现 DOMAIN\User。我基本上想深入了解并获取全名、电子邮件地址等信息。
我只需要一个有用的链接,但我所做的搜索似乎没有找到任何结果!
非常感谢
I am trying to make use of the active directory membership rather than SQL but there is very limited documentation available online. I have managed to connect my application to the domain controller without any problems but when you use "Context.User.Identity.Name" it comes up with DOMAIN\User. I want to basically drill down and get information such as full name, e-mail address, etc.
I just need a useful link and the searching I have done doesn't appear to have got me anywhere!
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该会给您一些线索: http://msdn.microsoft.com /en-us/library/ms973834.aspx
以下是您可能想要在搜索结果中使用的 LDAP 属性列表: http://www.computerperformance.co.uk/Logon/LDAP_attributes_active_directory.htm
This should give you a bit of a clue: http://msdn.microsoft.com/en-us/library/ms973834.aspx
and here is a list of LDAP properties that you might want to play around with in the search result: http://www.computerperformance.co.uk/Logon/LDAP_attributes_active_directory.htm
你试过这个医生吗?
http://msdn .microsoft.com/en-US/library/system.web.security.activedirectorymembershipprovider%28v=vs.90%29.aspx
可以帮忙吗?
Have you tried with this doc?
http://msdn.microsoft.com/en-US/library/system.web.security.activedirectorymembershipprovider%28v=vs.90%29.aspx
Can help?
如果您正在使用 Active Directory,那么您可能会使用 Windows 身份验证。如果是这样,您需要做的就是:
参考
System.DirectoryServices.AccountManagement
在代码中(也许控制器操作或模型构造函数)
// 将您的域建立为用户查找的上下文
varprincipalContext = newPrincipalContext(ContextType.Domain, "domainName");
//获取当前用户的UserPrincipal对象
var userPrincipal.FindByIdentity(principalContext, @User.Identity.Name)
// 例子
var email = userPrincipal.EmailAddress;
注意:
这是有效的,因为 Windows 身份验证意味着当前
HttpContext
上的User.Identity
是WindowsIdentity
,因此它的Name< /code> 属性可用于搜索 AD。
您不仅限于查找当前用户。您可以使用 FindByIdentity() 来搜索传递的任何值,并且此方法存在于其他主体(例如 GroupPrincipal)上。您还可以指定希望通过其他类型进行搜索,例如 SID 而不是名称。
享受!
If you are making use of Active Directory then you are likely using Windows Authentication. If so, all you need to do is:
Reference
System.DirectoryServices.AccountManagement
In code (perhaps a controller action or model constructor)
// establishes your domain as the context for your user lookup
var principalContext = new PrincipalContext(ContextType.Domain, "domainName");
// gets the current user's UserPrincipal object
var userPrincipal.FindByIdentity(principalContext, @User.Identity.Name)
// example
var email = userPrincipal.EmailAddress;
Note:
This works because Windows Authentication means
User.Identity
on the currentHttpContext
is aWindowsIdentity
and thus itsName
property can be used to search AD.You aren't limited to looking up the current user. You can use
FindByIdentity()
to search any value passed, and this method exists on other principals (ex. GroupPrincipal). You can also designate you wish to search by another type such as SID instead of Name.Enjoy!