0

In my web app, I have a login.aspx page. When I enter the username and password, I need to validate it on a remote server. They only provide me the server name (path), and domain name (don't know the password and username). How can it be done?

My web.config

  <authentication mode="Forms">
    <forms loginUrl="Login.aspx" timeout="10"/>
  </authentication>

I have read LDAP Authentication in ASP.Net MVC but, in the membership provider, they wrote in the connection, password and username.

What should i do?

Community
  • 1
  • 1
ARATHY
  • 349
  • 5
  • 13
  • 29

2 Answers2

1

Like the answer there says:

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.

It depends on the configuration of the server how you should authenticate.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
1

If all you need to do is verify that the user exists and the password is valid, you can use something like this: The arguments are domain name, USER id and USER password. Since we're not querying anything, non-admin privileges are OK.

public static bool LogonValid(string ldapDomain, string userName, string password) {
    DirectoryEntry de = new DirectoryEntry(@"LDAP://" + ldapDomain, userName, password);

  try {
    object o = de.NativeObject;
    return true;
  }
    catch (Exception ex) {
    logger.Error(ex.ToString());
    return false;
  }
}

There are probably reasons that this won't work in every situation, but it's worked for me so far.

Brad Bruce
  • 7,638
  • 3
  • 39
  • 60
  • thankyou..but it shows an error when running remotely : "Request for the permission of type 'System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed." can you help me please ? @Brad Bruce – ARATHY Jun 27 '13 at 05:54
  • My app runs with full trust. It sounds like you are running with a lower trust level. Here's an article that describes a way to add just the required permission. http://ammarfassy.wordpress.com/2012/07/10/system-security-securityexception-request-for-the-permission-of-type/ – Brad Bruce Jun 27 '13 at 11:22