LDAP Authentication in ASP.Net MVC

前端 未结 5 508
野的像风
野的像风 2020-12-04 09:49

I want to be able to authenticate a user by using their domain UserId and Password, but the default ASP.Net MVC application allows the user to register a userId and password

5条回答
  •  醉酒成梦
    2020-12-04 10:55

    This is how to do it in web Apps forms authentication so it may need some adapting for MVC. Use the asp.net membership and roles engine. Setup the provider to use the Active Directory Membership provider AND ALSO use forms for authentication.

    
                  
      
    

    or something like it....

    The provider setup will look something like this:

    
      
        
      
    
    

    The connection protection, user name and pwd are for the account that has access to query AD on behalf of the system. Depending on the security of your network this may have to be setup or you won't be able to query AD to authenticate the user.

    Your connection string will look something like:

    
      
    
    

    The connection string can take many forms so you may have to research it for your environment.

    For the login page you might have to execute the authentication method and test...

        e.Authenticated = Membership.ValidateUser(username, password);
        if (e.Authenticated == false)...
    

    Stephen Shackow's book "Professional ASP.Net 2.0 Security, Membership, and Role Management" has a good coverage on using AD Membership (Chapter 12). It's not in the context of MVC but the configuration and setup would be the same.

提交回复
热议问题