Link to home
Start Free TrialLog in
Avatar of salvatore imparato
salvatore imparatoFlag for Italy

asked on

Check if user is in Group (ldap adsi WIN NT)

I know:
Name of server is DIP
Name of Group is Farm_group

I need a page with code in ASP classic NO NET!...
create a page in ASP with a box and button.
In the box the user insert the username and after pressing the button controll if the user is in Group on AD Winnt server.

If user is in group goto OK_page.asp if thje user not is in group appera message yopu noet are in "Farm_Group , access denied"

Possible?
Avatar of ddrudik
ddrudik
Flag of United States of America image

See if this example project fits what you need:
http://www.codeproject.com/KB/asp/webactivedirlogin.aspx
Avatar of salvatore imparato

ASKER

Hi ddrudik, tks for link...
But i want to check user in specific group not username and password in winnt ad....
ASKER CERTIFIED SOLUTION
Avatar of ddrudik
ddrudik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Peraphs solved 85% with the code here...

1) but ho to read via code the name of user logged and assing to the var  sUserName...instead  "oi24683"
?????

2) ho to show message in asp page if, after the select case not have success
?????

<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Nuova pagina 1</title>
</head>

<body>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
'http://p2p.wrox.com/topic.asp?TOPIC_ID=7848

Set oNetwork = CreateObject("WScript.Network")

sDomain = "DIP"
sUserName = "OI24683"

'sUserName = oNetwork.UserName
'sUserName = request.servervariables("AUTH_USER")

Set oUser = GetObject("WinNT://" & sDomain & "/" & sUserName & ",user")

For Each oGroup In oUser.Groups
Select Case(oGroup.Name)
    Case "InpdapNAXX"
    'Response.write("InpdapNAXX")
    Response.Redirect("./default.html")
    Case "Group B"
    'response.write("Yay")
    Response.Redirect("A.asp")
    Case "Group C"
    response.Redirect("Z.asp")
    Case "Group D"
    Response.redirect("Y.asp")
End Select
Next
%>

</body>

</html>
</form>
Avatar of jitganguly
jitganguly

1.For request.servervariables("AUTH_USER")  to work try unticking "Integrated Windows Authentication" in the same area where you untick anynomous access.

MS seems to think that this is the only solution:
SYMPTOMS
Accessing the Request.ServerVariables("LOGON_USER") variable from Active Server Pages (ASP) returns an empty string.

CAUSE
The LOGON_USER variable is not populated if the ASP page is accessed using Allow Anonymous security.

In order for the LOGON_USER variable to be populated, the user must be authenticated using either Basic or NT Challenge/Response security.

2. USe
Case else
response.write "no redirection"
response.end
hum........

Now i think.
Is possible to adjust the script in this mode:
insert 2 box in asp page:
username
password

authetnticate the user in domain, if the user with user name and password is authenticate use the filed of username to fill the var susername var....

Wath you think about?

naturally use attention message if user and password not are matched...
First let me know if the suggestions are working
ok ....
But understand my suggestion?
(my english is a napolitan english)
:-)
:-)
Ok. Lets try to fix your current problems and then we can always enhance it
nice!!!
Tks for patience.
Pizza are ready for you.
what about hot wings ?
just found tath and it work on my domain:
<form method="post">  
      <table align="center" border="0" cellpadding="5" cellspacing="0" width="400">
          <tr>
            <td align="right">Domain:</td>
            <td><input type="text" size="30" name="domain" value="" /></td>
          </tr>
          <tr>
            <td align="right">User:</td>
            <td><input type="text" size="30" name="username" value="" /></td>
          </tr>
          <tr>
            <td align="right">Password:</td>
            <td><input type="password" size="30" name="password" value="" /></td>
          </tr>
          <tr>
            <td align="center" colspan="2"><input type="submit" value="Login" name="cmdLogin" /></td>
          </tr>
      </table>
</form>

<%
On Error Resume Next
If Request.Form <> "" Then
      strUserName = Request.Form("username")
      strPassword = Request.Form("password")
      strDomain = Request.Form("domain")
      strADsPath = "WinNT://" & strDomain
      Set oADsObject = GetObject(strADsPath)
      Set oADsNamespace = GetObject("WinNT:")
      Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strDomain & "\" & strUserName, strPassword, 0)
      If Err.Number = 0 Then              
        Response.Write "<h2>Authenticated</h2>"        
      Else
        Response.Write "<h2>Login Failed</h2>"
      End If
End If
%>
Not uset the box domain i want to isert to the defaul in script....
>>Not uset the box domain i want to isert to the defaul in script....

Sorry didn't understand your 'napolitan english'.Could u explain more
Hi jitganguly not consider last note: Not uset the box domain i want to isert to the defaul in script....