p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Professional (http://p2p.wrox.com/forumdisplay.php?f=63)
-   -   Connecting to AD (http://p2p.wrox.com/showthread.php?t=98828)

Vitorneto April 25th, 2016 10:01 AM

Connecting to AD
Hello ladies and gentlemen

I have "gathered" code from different sources and managed to be able to connect to my AD.

what i need and i am asking on my knees, is that i get redirected to a welcome page.

Also if i have a logout link on the welcome.asp page how can i logout from the AD (Active directory)

Below is the code

-----------------------------filter user---------------------------
fsCompletted = Request.QueryString("f")

If fsCompletted = 1 Then
ResultHTML = ProcessForm
ResultHTML = "<br>"
End If

Function ProcessForm
on error resume next
strUserName = Right(oUsername, Len(oUsername) - InStrRev(oUsername, "\"))
if InStr(strUserName, "@")>0 then
strUserName = Left(strUserName, InStr(strUserName, "@")-1)
end if
Set objDomain = GetObject("GC://rootDSE")
objADsPath = objDomain.Get("defaultNamingContext")
Set objDomain = Nothing
Set con = Server.CreateObject("ADODB.Connection")
con.provider ="ADsDSOObject"
con.Properties("User ID") = oUsername
con.Properties("Password") = oPassword
con.Properties("Encrypt Password") = False
con.open "Active Directory Provider"
Set Com = CreateObject("ADODB.Command")
Set Com.ActiveConnection = con
Com.CommandText ="select name,telephonenumber,mail FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
Set rs = Com.Execute
VarInfo="<p>"+rs("name")+"<br>"+rs("telephonenumbe r")+"<br >"+rs("mail")+"</p>"
if err.number=0 then
HTML = "<p>"+rs("name")+"<br>"+rs("telephonenumber")+ "<br >"+rs("mail")+"</p>"
HTML = "<p>Not Authenticated</p>"
end if
Session("mail") = Rs("mail")
Set rs = Nothing
Set con = Nothing
Response.Redirect "x4_page.asp"

'ADUSER = rs("mail")
Session("userid") = VarInfo
End Function
PostURL = Request.ServerVariables("SCRIPT_NAME") & "?f=1" %>
<%if request.querystring("f")="" then %>
<form method="post" Action="<%=PostURL%>">
<p>Username : <input type="text" Name="username" value="" Size="25">(yourDomain/username)</p>
<p>Password : <input type="password" Name="password" Size="25"></p>
<input Name=SubmitButton Value="Authenticate User" Type=submit>
<%end if%>

--<%Response.Write Session("mail")%>

All times are GMT -4. The time now is 08:13 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.