Search Active Directory - security error

S

steve

I have the following code in an infopath form - i get a security
exception on the line:
rootDse = New DirectoryEntry("LDAP://rootDSE")

The same code works fine if i build the app as a Windows Application.

any ideas?

Dim domainSid() As Byte
Dim rootDse As DirectoryEntry
Dim domainRoot As DirectoryEntry
Dim searcher As DirectorySearcher
Dim results As SearchResultCollection
Dim objCollResultProperty As ResultPropertyCollection
Dim objCollResultPropertyValue As
ResultPropertyValueCollection
Dim result As SearchResult

rootDse = New DirectoryEntry("LDAP://rootDSE")
domainRoot = New DirectoryEntry("LDAP://" +
DirectCast(rootDse.Properties("defaultNamingContext").Value, String))

searcher = New DirectorySearcher(domainRoot)
domainSid =
DirectCast(domainRoot.Properties("objectSID").Value, Byte())
searcher.Filter = ("(&(objectClass=user)(samaccountname=" &
Environment.UserName() & "))")
searcher.Filter = ("(&(objectClass=user)(samaccountname=" &
"kstarkey" & "))")

results = searcher.FindAll()
result = results.Item(0)

objCollResultProperty = result.Properties

objCollResultPropertyValue =
objCollResultProperty.Item("displayname")
Dim GetName As String

GetName = objCollResultPropertyValue.Item(0)

'thisXDocument.DOM.selectSingleNode("//my:singleName").text
= GetName

results.Dispose()
searcher.Dispose()
domainRoot.Dispose()
rootDse.Dispose()
 
S

S.Y.M. Wong-A-Ton

What is the full security error message? I suspect you may be having a code
access security issue and may have to give your form full trust for it to
work.
 
S

steve

Thanks for responsing. The full message is:

System.Security.SecurityException
Security error.
at
Absence_Request_Trusted.Absence_Request_Trusted.OnLoad(DocReturnEvent
e)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent
pEvent)


I could make the form fully trusted since all the users are internal to
our project and there are not that many users. Can I run RegForm with
an InfoPath form that uses Managed Code? The form itself doesn't seem
to be in the Visual Studio Project/Absence Request etc... folder as i
expected (I'm new to this, probably a stupid question)

the other complication is that I want to ultimately store the form on
SharePoint. I've read that RegForm forms can be used w/ SharePoint,
and I've also read the opposite.

thanks again

steve
 
S

steve

Thanks for responsing. The full message is:

System.Security.SecurityException
Security error.
at
Absence_Request_Trusted.Absence_Request_Trusted.OnLoad(DocReturnEvent
e)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent
pEvent)


I could make the form fully trusted since all the users are internal to
our project and there are not that many users. Can I run RegForm with
an InfoPath form that uses Managed Code? The form itself doesn't seem
to be in the Visual Studio Project/Absence Request etc... folder as i
expected (I'm new to this, probably a stupid question)

the other complication is that I want to ultimately store the form on
SharePoint. I've read that RegForm forms can be used w/ SharePoint,
and I've also read the opposite.

thanks again

steve

I see the form now - it's in the BIN/DEBUG folder......... (weird) -
should i run RegForm against that, and then publish the result to
SharePoint?
 
S

S.Y.M. Wong-A-Ton

This does not look like a code access security permission error, so giving
your form full trust might not solve the problem. Perhaps the user account
being used to access Active Directory does not have permission to do so?

There are 2 ways to give your form full trust: 1. Install it using regform
or 2. sign it with a digital certificate. I meant the latter. Since the form
template will be published to SharePoint, it is best to use the second option.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top