活动目录身份验证
我在asp.net中制作了一个Web应用程序。在我的项目中,身份验证是通过匹配数据库中的用户名和密码来完成的。但现在客户要求我在Active Directory身份验证的帮助下自动登录应用程序。客户询问建议我使用 AD 中用户的电子邮件 ID 进行身份验证。
我尝试获取 AD 中的记录,我可以获取用户的全名,但无法获取电子邮件 ID,
我尝试了代码:
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
string[] a = Context.User.Identity.Name.Split('\\');
System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
string Name = ADEntry.Properties["FullName"].Value.ToString();
此外,我使用 DirectorySearcher 但它生成了无法在客户端服务器中搜索记录的错误..
I am have made one web application in asp.net.In my project Authentication was done by matching the username and password in database.But now client ask me for the auto login in application with the help Of Active Directory authentication. Client ask suggest me to use the Email Id of user in AD for the authentication.
I tried to fetch the records in the AD, I could fetch the Fullname of user but I couldn't get the Email id,
I tried the code:
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
string[] a = Context.User.Identity.Name.Split('\\');
System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
string Name = ADEntry.Properties["FullName"].Value.ToString();
Further more I Use DirectorySearcher but it genterates Error that Coulnot search the record in the client server..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在为一家公司制作门户网站时遇到了完全相同的情况。
如果他们不希望您进入他们的 AD,那么您可以请求获得门户访问权限的人员的 NTLogins。创建一个简单的表,其中包含 NTLogin,并使用正在访问门户的系统进行身份验证。
查看我使用的示例代码。
并确保您的 web.config 文件中具有 Windows 身份验证模式
希望这会有所帮助。
I had the exact same situation while making a portal for a company.
If they dont want you to get into their AD then what you can do is to request for the NTLogins of the people who will be given access to the portal. make a simple table which have their NTLogin and simply authenticate using the system from which the portal is being accessed.
Check out the sample code i used.
And making sure that you have authentication mode to windows in your web.config file
Hope this helps.
为了读取 AD 数据,我使用这个类。它是为我们的 AD 设置的,但基本上您可以在参数中传递您想要查找的所有“字段”。
但您需要知道哪个字段包含电子邮件地址。 Sysinternals 制作了一个非常好的浏览 AD 的工具,可以找出您要查找的内容,称为 ADExplorer。
但我不明白为什么你需要看AD?如果用户在网络上,您不能假设用户已经通过身份验证,然后依赖 Windows 身份吗?
For reading AD data, i use this class. It is setup for our AD, but basically you can just pass in all the "fields" you want to find, in the params.
But you need to know what field holds the email address. Sysinternals made a pretty good tool for browsing AD, to figure out what you are looking for, called ADExplorer.
But I don't understand why you need to look in the AD? Can you not assume that the user is already authenticated, if they are on the network, and then rely on the windows identity?