Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

Problem - Forms Authentication against AD

Last post 06-27-2008, 2:22 AM by dunnry. 4 replies.
Sort Posts: Previous Next
  •  06-25-2008, 6:24 AM 4029

    Problem - Forms Authentication against AD

    Hi All,

    I am trying to do Forms Authentication against Active Directory and have got everything working expect for that I can authenticate with any domain information. Please find the code and flow below and let me know what could be wrong.

    Step 1. User is prompted for credentials - UserName, Password, Domain

    Step 2. Users submits the page.

    Step 3. Execute code below

    Dim adPath As String = "LDAP:// OUR DOMAIN NAME")

    Dim domainAndUsername As String = domain & "\" & username

    Dim entry As DirectoryEntry = New DirectoryEntry(adPath, domainAndUsername, pwd, AuthenticationTypes.Secure)

    Try

    'Bind to the native AdsObject to force authentication.

    Dim obj As Object = entry.NativeObject

    Dim search As DirectorySearcher = New DirectorySearcher(entry)

    search.Filter = "(SAMAccountName=" & username & ")"

    search.PropertiesToLoad.Add("cn")

    Dim result As SearchResult = search.FindOne()

    If (result Is Nothing) Then

    Return False

    End If

    'Update the new path to the user in the directory.

    adPath = result.Path

    _filterAttribute = CType(result.Properties("cn")(0), String)

    Catch ex As Exception

    Throw New Exception("Error authenticating user. " & ex.Message)

    End Try

    Now user is still authenticated though the user has entered correct username and password and an invalid Domain Name. Don't know what is causing this?

    Thanks and Regards,

    Parag

     

  •  06-25-2008, 2:43 PM 4035 in reply to 4029

    Re: Problem - Forms Authentication against AD

    Use the ActiveDirectoryMembershipProvider class.  Don't do this yourself manually.


    Ryan Dunn
    Extemporaneous Mumblings
    The .NET Developer's Guide to Directory Services Programming
  •  06-26-2008, 5:33 AM 4048 in reply to 4035

    Re: Problem - Forms Authentication against AD

    Thanks Ryan.

    However, we can't use it as we have only .NET 1.1 installed. (unless it could be used with it)

    Thanks and Regards,

    Parag

  •  06-27-2008, 1:47 AM 4055 in reply to 4048

    Re: Problem - Forms Authentication against AD

    You'd be much better off finding a way to add .NET 2.0 to the web server.  .NET 2.0 isn't exactly new at this point.  NET 3.5 is still a bit new, but it still isn't even that new. 

    That said, I've heard of this issue before but I don't know what causes it or how to get around it.  Perhaps you could just call LogonUser instead?

  •  06-27-2008, 2:22 AM 4059 in reply to 4048

    Re: Problem - Forms Authentication against AD

    Bummer.  As Joe mentions, life is a lot easier with .NET 2.0 here.  However, what is the AD version you are hitting?  I am wondering if you have allowed anonymous access (in Windows 2000 perhaps).

    Ryan Dunn
    Extemporaneous Mumblings
    The .NET Developer's Guide to Directory Services Programming
View as RSS news feed in XML