DirectoryEntry causing error in Sharepoint web part
I'm trying to create a sharepoint web part (in vb.net) to access some AD attributes. My function works fine in a windows app, but I get an "System.Security.SecurityException: Security error." error when I place it in my sharepoint site. Here's the description of the error:
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
The line that it actually errors out on is where I declare an directory entry:
Dim odomain As DirectoryEntry = New DirectoryEntry("LDAP://" & sDomain, sUsername, sPassword)
I have the trust leve in my web config file as wss_medium.
Any help with this issue would be greatly appreciated since I'm really out of troubleshooting options.