Click here to Skip to main content
14,971,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am very new to the legacy Classic ASP and trying to set up an intermediate authentication page for a classic asp application using vbScript.I need to check for LDAP authentication and on its success to verify the availability of the user in a local DB to verify the signup for the tool. Here is the code below (referred from various websites around the internet) not working for me and throwing Http 500 Internal Server error. Since I am not sure how to debug and what error it really is,I am stuck with no ideas.Am I missing anything?? The application is hosted in IIS 7.5 with default app pool on Integrated mode.

It would be good, if some one give me some insight on this

What I have tried:

<html>
<head></head>
<body>
<%
on error resume next
dim strUser,strQuery,oConn,cmd,oRS,AuthenticateUser,strPwd

strUser= Replace(Trim(Request("userid")),"'","`")
strPwd= Request("upassword")
strservername = "mydomain.com:389"
AuthenticateUser = false
strQuery = "SELECT cn FROM 'LDAP://" & strservername & "' WHERE objectClass='user'"
set oConn = server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = strUser
oConn.Properties("Password")= strPwd
oConn.Properties("Encrypt Password") = true
oConn.open "ADs Provider", strUser,strPwd
set cmd = server.CreateObject("ADODB.Command")
set cmd.ActiveConnection = oConn
cmd.CommandText = strQuery

set oRS = cmd.Execute
If Err.number <> 0 then
Response.Redirect "index.asp?errvar=" &Err.number & Err.description
'Response.Write Err.description &"
"
'Response.End
End If
if oRS.bof or oRS.eof then
AuthenticateUser = false
else
AuthenticateUser = true
end if
set oRS = nothing
set oConn = nothing

'CHK THE DATABASE FOR THE USER Availability
If AuthenticateUser = true
on error resume next
dim sql, Rs1
sql="Query to check the user available in the tool DB"
Set Rs1 = ObjConn.Execute(sql)
If Err.number <> 0 then
Response.Write "ERROR OCCURED" &"
"
Response.Write Err.description &"
"
Response.End
End If

If Not Rs1.EOF Then
UserID=Trim(Rs1("UserID"))
End If

Rs1.Close
Set Rs1 = Nothing

If UCase(UserID) = UCase(Request("UserID")) Then

Session("UserId") = UserId
%>
<form action="" method="POST" name="form1">
<input type="hidden" name="userid" value="<%=UserID%>">
</form>
<script>
document.form1.action="Home.asp";
document.form1.submit()
</script>
<%End If%>
<%Else%>
<form action="" method="POST" name="form1">
<input type="hidden" name="Flag" value="1">
</form>
<script>
document.form1.action="index.asp";
document.form1.submit()
</script>
<%End If%>
</body>
</html>


Posted
Updated 6-May-21 11:03am
Comments
Richard Deeming 19-Feb-16 12:08pm
   
Why are you writing a new application in a technology that's been dead and buried for 15 years?

You're going to struggle to find anyone who remembers how it works, and you're going to bump into lots of things that it can't do because they weren't around when it was being maintained.

ASP.NET would be a much better choice.

Finally the below script worked for me:


<html>
<head></head>
<body>
0 then
Response.Write "ERROR OCCURED" &"
"
Response.Write Err.description &"
"
Response.End
End If

If Not Rs1.EOF Then
UserID=Trim(Rs1("UserID"))

End If
End If
Rs1.Close
Set Rs1 = Nothing

If UCase(UserID) = UCase(Request("UserID")) Then

%>]]>
<form action="" method="POST" name="form1">
<input type="hidden" name="userid" value="<%=UserID%>">
</form>
<script>
document.form1.action="Home.asp";
document.form1.submit()
</script>
]]>
<form action="" method="POST" name="form1">
<input type="hidden" name="Flag" value="1">
</form>
<script>
document.form1.action="index.asp";
document.form1.submit()
</script>
]]>
</body>
</html>
   
Hi there,

i am also trying to authenticate to ad and would like to get the name and email on the next page.

the script you have does it work now??
Can you post all of it??

many thanks
   
Comments
CHill60 7-May-21 5:11am
   
If you want to ask a question relating to a solution, then use the "Have a Question or Comment?" link next to the solution. Do not post follow up questions or comments as a "Solution" to the original post

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900