John John
John John

Reputation: 1

Can we use "MembershipProvider" inside ASP.NET Core MVC 3.1

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

Upvotes: 0

Views: 626

Answers (1)

Simmetric
Simmetric

Reputation: 1661

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

Upvotes: 1

Related Questions