J
Jon Delano
Hello
I am developing a ASP.NET site (using VB).
I found some code that allows me to authenticate the user trying to access
the site against the active directory server for the company.
What is happening is some users authenticate and others do not ... but they
are all a part of the domain.
The web server the site is running on is part of the domain (else no user
would authenticate)
Here is the code I use to authenticate the users :
' use the OLEDB provider to access the ADS Object, this allows for
simple SQL Query for the user.
Dim cn As New OleDb.OleDbConnection("provider=ADsDSOObject;User ID="
& txtUserName.Text & ";Password=" & txtPassword.Text)
Dim cmd As New OleDb.OleDbCommand("Select GivenName, sn from
'LDAP://[domain is here]' where samAccountName='" & txtUserName.Text & "'",
cn)
Dim dtrdr As OleDb.OleDbDataReader
Try
cn.Open()
dtrdr = cmd.ExecuteReader
If dtrdr.Read = True Then
' user authenticated against active directory
Session.Add("UserFirstName", dtrdr("GivenName"))
Session.Add("UserLastName", dtrdr("sn"))
UserIsPhysician()
If Session("PhysicianID") = -1 Then Exit Sub
Server.Transfer("patientlist.aspx")
Else
Label1.Text = "Unable to access user data."
End If
dtrdr.Close()
Catch ex As Exception
Dim exMsg As String
If InStr(ex.Message, "PERMISSION") > 0 Then
exMsg = ""
Else
exMsg = ex.Message
End If
Label1.Text = "Invalid Username or Password. " & exMsg
End Try
cmd = Nothing
dtrdr = Nothing
cn.Close()
cn = Nothing
I can't understand why some users will work fine and others just won't.
If anyone can offer any ideas ... it would be greatly appreicated.
Thank you
Jon
I am developing a ASP.NET site (using VB).
I found some code that allows me to authenticate the user trying to access
the site against the active directory server for the company.
What is happening is some users authenticate and others do not ... but they
are all a part of the domain.
The web server the site is running on is part of the domain (else no user
would authenticate)
Here is the code I use to authenticate the users :
' use the OLEDB provider to access the ADS Object, this allows for
simple SQL Query for the user.
Dim cn As New OleDb.OleDbConnection("provider=ADsDSOObject;User ID="
& txtUserName.Text & ";Password=" & txtPassword.Text)
Dim cmd As New OleDb.OleDbCommand("Select GivenName, sn from
'LDAP://[domain is here]' where samAccountName='" & txtUserName.Text & "'",
cn)
Dim dtrdr As OleDb.OleDbDataReader
Try
cn.Open()
dtrdr = cmd.ExecuteReader
If dtrdr.Read = True Then
' user authenticated against active directory
Session.Add("UserFirstName", dtrdr("GivenName"))
Session.Add("UserLastName", dtrdr("sn"))
UserIsPhysician()
If Session("PhysicianID") = -1 Then Exit Sub
Server.Transfer("patientlist.aspx")
Else
Label1.Text = "Unable to access user data."
End If
dtrdr.Close()
Catch ex As Exception
Dim exMsg As String
If InStr(ex.Message, "PERMISSION") > 0 Then
exMsg = ""
Else
exMsg = ex.Message
End If
Label1.Text = "Invalid Username or Password. " & exMsg
End Try
cmd = Nothing
dtrdr = Nothing
cn.Close()
cn = Nothing
I can't understand why some users will work fine and others just won't.
If anyone can offer any ideas ... it would be greatly appreicated.
Thank you
Jon