This documentation is archived and is not being maintained.

ActiveDirectoryMembershipProvider.GetUserNameByEmail Method

Gets the user name associated with the specified e-mail address.

Namespace:  System.Web.Security
Assembly:  System.Web (in System.Web.dll)

[DirectoryServicesPermissionAttribute(SecurityAction.Demand, Unrestricted = true)]
[DirectoryServicesPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
[DirectoryServicesPermissionAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)]
public override string GetUserNameByEmail(
	string email


Type: System.String
The e-mail address to search for.

Return Value

Type: System.String
The user name associated with the specified e-mail address.


email exceeds 256 characters

- or -

after trimming, email is empty.


More than one user exists in the data store with the same e-mail address and the RequiresUniqueEmail property value is true.


The provider is not initialized.

This method is called by the Membership class to retrieve a user name from the Active Directory data store based on the e-mail address for the user.

If more than one user in the membership data store has the same e-mail address, the first user name encountered is returned. You can set the requiresUniqueEmail attribute of the membership Element (ASP.NET Settings Schema) element to true in the application configuration file to ensure that each e-mail address in the database is unique.

Leading and trailing spaces are trimmed from the email parameter value. If the e-mail address is empty after trimming, an ArgumentException is thrown. If the e-mail address is null, all user names in the Active Directory data store are searched, and the first user name is returned.

We recommend that you do not enable searching on production systems until you have confirmed that the search queries issued by the ActiveDirectoryMembershipProvider class do not adversely impact your directory server's performance.

Important noteImportant

The GetUserNameByEmail method will run even when the EnableSearchMethods property is false.

Since the ActiveDirectoryMembershipProvider class is designed for a stateless Web environment, it is unable to use the paging optimizations exposed by the underlying System.DirectoryServices APIs. This means that paging operations during searches against large directories are very expensive and should be avoided. Search operations are always issued against the directory server configured in the connection string, or an automatically selected server in the case of a connection string pointing at a domain. The provider does not use a global catalog for its search methods.

The provider uses a subtree search starting at the search point specified in the connection string. See the ActiveDirectoryMembershipProvider class topic for more information about connection strings.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.