While @Michael Liu's answer is correct, it's not easily understood by a novice (such as myself) with limited working knowledge in this area. This answer is intended to supplement Michael's answer.
When your web.config is configured to use a trust level that is anything other than "full"
<trust level="Full"/>
then you will not be able to connect to Active Directory without creating your own policy file. Once you have created your own policy file (let's say it's called "myPolicyFile.config") then you're ready to customize it in order to allow your ASP.NET application to connect to Active Directory.
Here are the changes that you need to make:
In web.config, configure the website to use your custom policy file:
<system.web>
...
<securityPolicy>
<trustLevel name="myMediumPolicy" policyFile="myPolicyFile.config"/>
</securityPolicy>
<trust level="myMediumPolicy"/>
...
</system.web>
Next, in your myPolicyFile.config file, add the "SecurityClass" and "IPermission" entries as shown in the following:
<configuration>
...
<PolicyLevel version="1">
<SecurityClasses>
....
<SecurityClass Name="DirectoryServicesPermission" Description="System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
....
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
...
<IPermission
class="DirectoryServicesPermission"
version="1"
Unrestricted="true"
/>
<IPermission
class="SecurityPermission"
version="1"
Flags="Execution, ControlThread, ControlPrincipal, RemotingConfiguration, UnmanagedCode"
/>
...
</PermissionSet>
</NamedPermissionSets>
</PolicyLevel>
...
</configuration>
Note: the <IPermission class="SecurityPermission"... /> node may already exist (depending on which system defined trust-level file you based your myPolicyFile.config file). If it already exists then you just need to add the text ", UnmanagedCode" to the "Flags" attribute. If it does not already exist then copy and paste the example above into the "ASP.Net" NamedPermissionSet.
Finally, save your changes and reload your website. You should be good to go!