ASP.NET MVC:如何设置 web.config 进行 LDAP 身份验证?
我有一个具有以下参数的工作 LDAP 服务器:
OU=users,OU=mydomain,O=this domain
LDAP://myhost:389
我成功访问使用通用 ldap 客户端,就像 Jarek Gawor 的 LDAP 浏览器/客户端一样,具有以下设置:
OU=users,OU=mydomain,O=this domain
User info (append base DN):
uid=myid
password=mypwd
我尝试与 ASP.NET 相同,总是收到错误“用户名或密码错误”。 您可以帮我使用上述参数设置 web.config 吗? 我做了很多尝试,例如更改连接用户名、删除域名、放置 uid=myid 等...
web.config
<configuration>
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://myhost:389"/>
....
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionProtection="None"
connectionUsername="MYDOMAIN\myid"
connectionPassword="mypwd"
attributeMapUsername="sAMAccountName"
enableSearchMethods="True" />
</providers>
</membership>
......
提前致谢
I have a working LDAP Server with these parameters:
OU=users,OU=mydomain,O=this domain
LDAP://myhost:389
I successfully access with a generic ldap client, like the good Jarek Gawor's ldap browser/client with following settings:
OU=users,OU=mydomain,O=this domain
User info (append base DN):
uid=myid
password=mypwd
I tried to to the same with ASP.NET, getting always the error "wrong username or password".
May you help me to setup web.config with above parameters, please?
I did many tries, like changing connectionUsername, removing domainname, putting uid=myid, etc...
web.config
<configuration>
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://myhost:389"/>
....
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionProtection="None"
connectionUsername="MYDOMAIN\myid"
connectionPassword="mypwd"
attributeMapUsername="sAMAccountName"
enableSearchMethods="True" />
</providers>
</membership>
......
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我成功地使其与以下 web.config 设置一起工作。
有两个问题/错误:
1)我没有指定容器,所以我遵循@Kevin的提示:
我认为这与CN相关,而O可以在这里省略,但我不认为这非常重要...
第二)我将 DN 基础和用户名(以 uid= 的形式)放在 connectionUsername 参数中:
请注意,就我而言,我需要输入 uid=myid。我不知道这是否是一个通用的解决方案;也许和我公司的ADAS配置有关,我不知道。我希望这可以帮助你们中的一些人...如果您发现这个解决方案有用,请投票,谢谢。
@凯文:非常感谢。你非常有帮助!
I succeeded in getting it work with the following web.config setup.
There were two problems/errors:
1st) I did not specify the container, so I followed @Kevin's hints:
I think that was relevant the CN, while O could be omitted here, but I do not think this is very important...
2nd) I put the DN base and username (in the form uid=) together inside connectionUsername parameter:
Please note, in my case I needed to put uid=myid. I do not know if this could be a general solution; perhaps it is related to ADAS configuration of my company, I do not know. I hope this can help some of you...please vote up if you find this solution useful, thx.
@Kevin: Thank you very much. You have been very helpful!
唯一缺少的项目似乎是默认的 ou。您是否尝试过在“/CN=Users,DC=testdomain1,DC=test,DC=com”下面添加尾随条目?
我从 http://msdn.microsoft.com/en-us/ 获得上述内容库/ff650307.aspx
The only item missing seems to be the default ou. Have you tried adding the trailing entry below "/CN=Users,DC=testdomain1,DC=test,DC=com" ?
I got the above from http://msdn.microsoft.com/en-us/library/ff650307.aspx
WebConfig
C# 代码
LoginRslt = adAuth.IsAuthenticated(ConfigurationSettings.AppSettings["LDAPDomain"].ToString(), _username, _password);
WebConfig
C# code
LoginRslt = adAuth.IsAuthenticated(ConfigurationSettings.AppSettings["LDAPDomain"].ToString(), _username, _password);