Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Write Cookie

Status
Not open for further replies.

digatle

Technical User
Oct 31, 2003
85
US
I've got the following code for specific needs to build a cookie:

<Identifying the User Logged on to a Remote Computer>

strComputer = &quot;RemoteComputer&quot;
Set objWMIService = GetObject(&quot;winmgmts:&quot; _
& &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
Set colComputer = objWMIService.ExecQuery _
(&quot;Select * from Win32_ComputerSystem&quot;)
For Each objComputer in colComputer
Wscript.Echo objComputer.UserName
Next

<Retrieving the Active Directory Groups a User Belongs To>

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D

Set objUser = GetObject _
(&quot;LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com&quot;)

intPrimaryGroupID = objUser.Get(&quot;primaryGroupID&quot;)
arrMemberOf = objUser.GetEx(&quot;memberOf&quot;)

If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo &quot;The memberOf attribute is not set.&quot;
Else
WScript.Echo &quot;Member of: &quot;
For each Group in arrMemberOf
WScript.Echo Group
Next
End If

Set objConnection = CreateObject(&quot;ADODB.Connection&quot;)
objConnection.Open &quot;Provider=ADsDSOObject;&quot;
Set objCommand = CreateObject(&quot;ADODB.Command&quot;)
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
&quot;<LDAP://dc=NA,dc=fabrikam,dc=com>;(objectCategory=Group);&quot; & _
&quot;distinguishedName,primaryGroupToken;subtree&quot;
Set objRecordSet = objCommand.Execute

While Not objRecordset.EOF
If objRecordset.Fields(&quot;primaryGroupToken&quot;) = intPrimaryGroupID Then
WScript.Echo &quot;Primary group:&quot;
WScript.Echo objRecordset.Fields(&quot;distinguishedName&quot;) & _
&quot; (primaryGroupID: &quot; & intPrimaryGroupID & &quot;)&quot;
End If
objRecordset.MoveNext
Wend

objConnection.Close


How do I take these two scripts and write an ASP page that generates a cookie with that information?

Digatle
 
I take it ASP can't write this even though its ASP code?

Digatle
 
intimidation and taunting will not genearte much help typically.


Response.Cookies should answer your question with a bit of work and research
eg:

_____________________________________________________________________
onpnt2.gif

Hakuna matata!!
 
I meant no harm in my quest for this. I'm a PHP programmer and no nothing about ASP. I was excited when another member here sent me to Microsoft for the two scripts here but I don't know what to do with them.

Digatle
 
sorry for coming off rude. coffee hadn't kicked in yet. [wink]

what portion of the scripts generated values are you looking to place in a cookie? If you want all the information to be in one cookie or two then I would simply set either a session variable while you do your looping while building on it. Then just response.cookie that final variable. You can also use form fields (hidden) if the sessions are something you don't want to get into.

eg:
While Not objRecordset.EOF
If objRecordset.Fields(&quot;primaryGroupToken&quot;) = intPrimaryGroupID Then
WScript.Echo &quot;Primary group:&quot;
WScript.Echo objRecordset.Fields(&quot;distinguishedName&quot;) & _
&quot; (primaryGroupID: &quot; & intPrimaryGroupID & &quot;)&quot;
Response.Write &quot;<input type=&quot;&quot;hidden&quot;&quot; name=&quot;&quot;myName&quot;&quot; value='&quot; & intPrimaryGroupID & &quot;##&quot; & objRecordset.Fields(&quot;distinguishedName&quot;) & &quot;'>&quot;
End If
objRecordset.MoveNext
Wend

at that point then you would genreate a hidden field such as
<input type=&quot;hidden&quot; name=&quot;myName&quot; value='ID##value'>

at this point you can do a double split in a loop through the form collection then as the form values would be sent delimited by a comma
as
value,value,value

so you split on the comma first
Dim myArrayOfmyNames
myArrayOfmyNames = split(Request.Form(&quot;myName&quot;),&quot;,&quot;)

then you just loop while the theres elements and do what you need with the values returned
Do While x <= ubound(myArrayOfmyNames)
x = x + 1
split by ## and write the cookies
Loop


_____________________________________________________________________
onpnt2.gif

Hakuna matata!!
 
What I need from Active Directory for our purposes is the following:

givenname
memberof

Obviously the givenname is just a single variable. But the memberof would hold all of the groups that the current person has access to. This way we can have Active Directory be our mediator for our intranet instead of another UMA (User Management and Administration). The biggest reason for using Active Directory is because it is our most &quot;up to date&quot; when it comes to our employee's. If you work here, you're in AD. Our other systems (tax purposes) we keep you in there for 7 years. That's bad because in our UMA you'd still be there. AD is our better solution.

Digatle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top