ASP.NET MVC: how to configure web.config for LDAP authentication?

I have a working LDAP server with these parameters:

OU=users,OU=mydomain,O=this domain LDAP://myhost:389 

I successfully accessed using the general ldap client , for example, a good browser / Jarek Gawor ldap client with the following settings:

 OU=users,OU=mydomain,O=this domain User info (append base DN): uid=myid password=mypwd 

I tried to do the same with ASP.NET, always getting the error " wrong username or password ". Can you help me configure web.config with the above options, please? I made many attempts, for example, changing the connection name, deleting the domain name, placing 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

+6
source share
3 answers

I managed to get it to work with the next web.config installation.

There were two problems / errors:

1st) I did not specify a container, so I followed @Kevin's prompts:

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

I think this was relevant for CN, while O could be omitted here, but I don’t think it is very important ...

2nd) I put the DN base and username (in the form of uid =) together inside the 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 that in my case I needed to set uid = myid. I do not know if this could be a general solution; perhaps this is due to my company's ADAS configuration, I don’t know. I hope this can help some of you ... please vote if you find this solution helpful, thanks.

@Kevin: Thank you very much. You were very helpful!

+2
source

The only missing item seems to be the default value. Have you tried adding the following 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 above from http://msdn.microsoft.com/en-us/library/ff650307.aspx

0
source

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);

0
source

Source: https://habr.com/ru/post/907171/


All Articles