ASP.NET MVC:如何设置 web.config 进行 LDAP 身份验证?

发布于 2024-12-29 19:03:41 字数 1244 浏览 0 评论 0原文

我有一个具有以下参数的工作 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掩耳倾听 2025-01-05 19:03:41

我成功地使其与以下 web.config 设置一起工作。

有两个问题/错误:

1)我没有指定容器,所以我遵循@Kevin的提示:

<configuration>
  <connectionStrings>
  <add name="ADConnectionString" connectionString="LDAP://myhost:389/O=this domain,CN=Users,DC=mydomain,DC=com"/>
  ....

我认为这与CN相关,而O可以在这里省略,但我不认为这非常重要...

第二)我将 DN 基础和用户名(以 uid= 的形式)放在 connectionUsername 参数中:

<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="uid=myid, O=this domain"
     connectionPassword="mypwd"
     attributeMapUsername="sAMAccountName"
     enableSearchMethods="True" />

请注意,就我而言,我需要输入 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:

<configuration>
  <connectionStrings>
  <add name="ADConnectionString" connectionString="LDAP://myhost:389/O=this domain,CN=Users,DC=mydomain,DC=com"/>
  ....

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:

<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="uid=myid, O=this domain"
     connectionPassword="mypwd"
     attributeMapUsername="sAMAccountName"
     enableSearchMethods="True" />

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!

黯然#的苍凉 2025-01-05 19:03:41

唯一缺少的项目似乎是默认的 ou。您是否尝试过在“/CN=Users,DC=testdomain1,DC=test,DC=com”下面添加尾随条目?

add name="TestDomain1ConnectionString" connectionString="LDAP://testdomain1.test.com/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" ?

add name="TestDomain1ConnectionString" connectionString="LDAP://testdomain1.test.com/CN=Users,DC=testdomain1,DC=test,DC=com"

I got the above from http://msdn.microsoft.com/en-us/library/ff650307.aspx

顾挽 2025-01-05 19:03:41

WebConfig

<add key="LDAPPath" value="LDAP://ip/DC=company,DC=com" />
<add key="LDAPDomain" value="ta" />

C# 代码

LoginRslt = adAuth.IsAuthenticated(ConfigurationSettings.AppSettings["LDAPDomain"].ToString(), _username, _password);

WebConfig

<add key="LDAPPath" value="LDAP://ip/DC=company,DC=com" />
<add key="LDAPDomain" value="ta" />

C# code

LoginRslt = adAuth.IsAuthenticated(ConfigurationSettings.AppSettings["LDAPDomain"].ToString(), _username, _password);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文