asp.net – 如何从Web应用程序中的客户端计算机获取AD凭据?
是否可以从Web应用程序中为客户端计算机上的用户获取Activedirectory凭据?
为了澄清,我正在设计一个将在客户的Intranet上托管的Web应用程序. 需要在访问应用程序时不提示应用程序的用户提供凭据,而是应该自动抓取登录到客户端计算机的用户的凭据,而无需用户交互. 解决方法
绝对.这对于Intranet应用程序尤其有用.
既然你没有指定你的环境,我会假设它是.NET,但这当然不是唯一可行的方法. 可以使用LDAP轻松查询Active Directory.如果您使用的是.NET,则可以执行类似于this code example或以下示例的操作.您也可以在SQL environments内完成. 如果您只需要Windows来处理身份验证,则可以设置例如0700的.NET Web应用程序.确保在IIS中为您的应用程序设置turn off Anonymous Logins.完成后,您将能够访问用户的Windows登录名并使用它进行进一步的安全检查(例如,他们在AD中的group/role membership). 您还可以使用Enterprise Library的Security Application Block来简化整个混乱. 这是一个简短的C#示例:(转换为VB.NET here) using System.DirectoryServices; /// <summary> /// Gets the email address,if defined,of a user from Active Directory. /// </summary> /// <param name="userid">The userid of the user in question. Make /// sure the domain has been stripped first!</param> /// <returns>A string containing the user's email address,or null /// if one was not defined or found.</returns> public static string GetEmail(string userid) { DirectorySearcher searcher; SearchResult result; string email; // Check first if there is a slash in the userid // If there is,domain has not been stripped if (!userid.Contains("")) { searcher = new DirectorySearcher(); searcher.Filter = String.Format("(SAMAccountName={0})",userid); searcher.PropertiesToLoad.Add("mail"); result = searcher.FindOne(); if (result != null) { email = result.Properties["mail"][0].ToString(); } } return email; } 您不必指定域控制器.对DirectorySearcher执行empty / default构造函数会导致它尝试自动查找 – 实际上,这是the preferred method. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – ASP.Net MVC中的实时视频聊天录制解决方案
- asp.net-mvc-3 – 使用Ninject 2.2全局动作过滤器的MVC 3依
- 如何/在哪里asp.net mvc处理解码和动作方法参数
- asp.net-mvc – .NET MVC:计算Web应用程序中的Action方法
- asp.net – 在同一行(左右)对齐标签和文本框
- 经过一段时间的工作,IIS / ASP.Net无法从WCF Web服务的web.
- 使用ASP.Net MVC 1.0安装nUnit
- asp.net-mvc – 持久化jqGrid列首选项
- ASP.NET ::在page_load期间,如何获取提交回发的控件的ID?
- 有人可以向我介绍asp.net路由语法吗?