0

We have the following ASP.NET MVC 5 web application >> and we authenticate the users against an LDAP using this method:-

[HttpPost]
        [AllowAnonymous]
        [ValidateInput(false)]
        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);
                    RedirectToAction("Index","Home");
                   
                }
                else
                {
                  
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                   
                    return View(model);
                }
                
          
                

            }
           
            return View(model);
        }

and here is the provider inside the web.config:-

<membership>
      <providers>
        <add name="TestDomain1ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="TestDomain1ConnectionString" connectionUsername="Administrator" connectionPassword="*****" attributeMapUsername="sAMAccountName"/>
       
      </providers>
    </membership>

<connectionStrings>
    <add name="TestDomain1ConnectionString" connectionString="LDAP://mydomain.com/CN=Users,DC=mydomain,DC=com"/>
  </connectionStrings>

my question is; if we can use the same approach to authenticate our users if we upgrade our web application from ASP.NET MVC-5 to ASP.NET Core MVC 3.1 ? If the answer is not, then what we can use to authenticate users using LDAP?

Thanks

John John
  • 1
  • 72
  • 238
  • 501

1 Answers1

1

Unfortunately Membership is part of ASP.NET old style. .Net Core has a successor in the form of the Identity framework but it doesn't support LDAP authentication.

Microsoft recommends to use Windows authentication if you're using an on-premise AD: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-6.0&tabs=visual-studio

Simmetric
  • 1,443
  • 2
  • 12
  • 20
  • but in our case the IIS where the application is hosted is on another domain compared the AD server.. so windows authentication will not work for us – John John Oct 12 '22 at 22:14
  • Apparently there is a Windows Compatibility Pack that contains LDAP authentication, see answer here: https://stackoverflow.com/questions/49682644/asp-net-core-2-0-ldap-active-directory-authentication – Simmetric Oct 13 '22 at 07:07