I am working on an asp.net mvc-5 web application. And I am using asp.net membership provider to authentication users against our ldap server using form authentication.
Here is the login action method:-
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
MembershipProvider domainProvider;
domainProvider = Membership.Providers["TestDomain1ADMembershipProvider"];
if (ModelState.IsValid)
{
// Validate the user with the membership system.
if (domainProvider.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
}
else
{
// Response.Write("Invalid UserID and Password");
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
return RedirectToLocal(returnUrl);
}
return View(model);
}
And the web.config file where I defined a <providers>
and a <connection string>
for ldap:-
<providers>
<add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="DomainConnectionString" connectionUsername="*****\administrator" connectionPassword="*****" attributeMapUsername="sAMAccountName"/>
</providers>
&
<connectionStrings>
<add name="DomainConnectionString" connectionString="LDAP://WIN-SPDev.tgroup.local/OU=Domain Controllers,DC=tgroup,DC=local"/>
</connectionStrings>
But now when a user enters his username/password the domainProvider.ValidateUser(model.UserName, model.Password)
always return false.
Can anyone advice on this please?
Thanks