ActiveDirectoryMembershipUser ActiveDirectoryMembershipUser ActiveDirectoryMembershipUser ActiveDirectoryMembershipUser Class

Definition

Exposes and updates membership user information stored in an Active Directory data store.

public ref class ActiveDirectoryMembershipUser : System::Web::Security::MembershipUser
[System.Serializable]
public class ActiveDirectoryMembershipUser : System.Web.Security.MembershipUser
type ActiveDirectoryMembershipUser = class
    inherit MembershipUser
Public Class ActiveDirectoryMembershipUser
Inherits MembershipUser
Inheritance
ActiveDirectoryMembershipUserActiveDirectoryMembershipUserActiveDirectoryMembershipUserActiveDirectoryMembershipUser
Attributes

Examples

The following code example demonstrates using properties on the ActiveDirectoryMembershipUser object on a Web page that may return user information from multiple membership data stores. Because the ActiveDirectoryMembershipUser object that underlies the MembershipUser object returned by the membership provider does not implement the LastActivityDate and LastLoginDate properties, the code first checks the type of the user object returned from the membership provider before displaying the contents of those properties.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
  {
    MembershipUser user =
        Membership.GetUser();

    userName.Text = user.UserName;
    emailAddress.Text = user.Email;

    // <Snippet2>
    if (user is ActiveDirectoryMembershipUser)
    {
      lastLoginDate.Text = "Not available";
      lastActivityDate.Text = "Not available";
    }
    else
    {
      lastLoginDate.Text = user.LastLoginDate.ToShortDateString();
      lastActivityDate.Text = user.LastActivityDate.ToShortDateString();
    }
    // </Snippet2>   
    
    // <Snippet3>
    System.Security.Principal.SecurityIdentifier sidValue =
      (System.Security.Principal.SecurityIdentifier)user.ProviderUserKey;

    sid.Text = sidValue.ToString();
    // </Snippet3>
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>User information</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table>
        <tr>
          <td>
            User name:</td>
          <td>
            <asp:Literal ID="userName" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Email Address:</td>
          <td>
            <asp:Literal ID="emailAddress" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Last Login Date:</td>
          <td>
            <asp:Literal ID="lastLoginDate" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Last Activity Date:</td>
          <td>
            <asp:Literal ID="lastActivityDate" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Security Identifier SID:</td>
          <td>
            <asp:Literal ID="sid" runat="server" /></td>
        </tr>
      </table>
    </div>
  </form>
</body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim user As MembershipUser = Membership.GetUser()
        
    userName.Text = user.UserName
    emailAddress.Text = user.Email
        
    ' <Snippet2>
    If TypeOf (user) Is ActiveDirectoryMembershipUser Then
      lastLoginDate.Text = "Not available"
      lastActivityDate.Text = "Not available"
    Else
      lastLoginDate.Text = user.LastLoginDate.ToString()
      lastActivityDate.Text = user.LastActivityDate.ToString()
    End If
    ' </Snippet2>
    
    ' <Snippet3>
    Dim sidValue As System.Security.Principal.SecurityIdentifier
    sidValue = CType(user.ProviderUserKey, System.Security.Principal.SecurityIdentifier)
    
    sid.Text = sidValue.ToString()
    ' </Snippet3>
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>User information page</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <table>
        <tr>
          <td>
            User name:</td>
          <td>
            <asp:Literal ID="userName" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Email Address:</td>
          <td>
            <asp:Literal ID="emailAddress" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Last Login Date:</td>
          <td>
            <asp:Literal ID="lastLoginDate" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Last Activity Date:</td>
          <td>
            <asp:Literal ID="lastActivityDate" runat="server" /></td>
        </tr>
        <tr>
          <td>
            Security Identifier SID:</td>
          <td>
            <asp:Literal ID="sid" runat="server" /></td>
        </tr>
      </table>
    </div>
  </form>
</body>
</html>

Remarks

The ActiveDirectoryMembershipUser object is used to represent a single membership user in the Active Directory membership data store. It exposes information about the membership user such as the email address, and provides functionality for the membership user such as the ability to change or reset his or her password.

An ActiveDirectoryMembershipUser object is returned by the application's membership provider whenever the application is configured to use an Active Directory data store. In an application that can be configured to use different data stores, or in an application that uses multiple data stores, you can refer to the base class, MembershipUser. Because the ActiveDirectoryMembershipUser object does not implement the LastActivityDate and LastLoginDate properties, you must be prepared to handle the NotSupportedException that is thrown when these members are accessed on an ActiveDirectoryMembershipUser object.

The ActiveDirectoryMembershipUser class implements internal optimizations used by the ActiveDirectoryMembershipProvider class to minimize the number of attribute updates that occur when calling the UpdateUser method. It also serializes the SecurityIdentifier representation (available in the ProviderUserKey property) so that an ActiveDirectoryMembershipUser object can be serialized and deserialized without throwing exceptions.

A ActiveDirectoryMembershipUser object is returned by the GetUser and CreateUser methods or as part of a MembershipUserCollection returned by the GetAllUsers, FindUsersByName, and FindUsersByEmail methods.

An ActiveDirectoryMembershipUser object is required by the UpdateUser method when you want to update the information for an existing membership user.

ActiveDirectoryMembershipUser properties are mapped to Active Directory attributes. The following table lists the ActiveDirectoryMembershipUser properties and their default attribute mappings.

Property Default directory attribute Can be mapped?
ProviderUserKey securityIdentifier No
UserName userPrincipalName Yes, but must be either userPrincipalName or sAMAccountName
Comment comment No
CreationDate whenCreated No
Email mail Yes, but must be a single-valued attribute of type Unicode String.
LastActivityDate n/a Not supported by ActiveDirectoryMembershipProvider.
LastLoginDate n/a Not supported by ActiveDirectoryMembershipProvider.
LastPasswordChangedDate pwdLastSet No
PasswordQuestion none, but must be mapped to an attribute if using question-and-answer security for password reset or retrieval. Yes, but must be a single-valued attribute of type Unicode String.
IsApproved User-Account-Control (AD)

mDS-UserAccountDisabled (ADAM)
No
IsLockedOut computed from lockoutTime and the AD lockout duration (AD on Windows 2000)

msDS-User-Account-Control-Computed (AD on Windows Server 2003)

msDS-User-Account-Control-Computed (ADAM)
No
LastLockoutDate If locked out due to too many bad password attempts, the lockout time attribute is returned.

If locked out due to too many bad password answer attempts, the value stored in the attribute defined by attributeMapFailedPasswordAnswerLockoutTime is returned.

If locked out due to both a bad password and too many bad password attempts, the most recent date/time value is returned.

If the account is not locked out, return 1/1/1753 for SQL compatibility.
No

Constructors

ActiveDirectoryMembershipUser() ActiveDirectoryMembershipUser() ActiveDirectoryMembershipUser() ActiveDirectoryMembershipUser()

Initializes a new instance of an ActiveDirectoryMembershipUser object for a class that inherits the ActiveDirectoryMembershipUser class.

ActiveDirectoryMembershipUser(String, String, Object, String, String, String, Boolean, Boolean, DateTime, DateTime, DateTime, DateTime, DateTime) ActiveDirectoryMembershipUser(String, String, Object, String, String, String, Boolean, Boolean, DateTime, DateTime, DateTime, DateTime, DateTime) ActiveDirectoryMembershipUser(String, String, Object, String, String, String, Boolean, Boolean, DateTime, DateTime, DateTime, DateTime, DateTime) ActiveDirectoryMembershipUser(String, String, Object, String, String, String, Boolean, Boolean, DateTime, DateTime, DateTime, DateTime, DateTime)

Creates a new instance of the ActiveDirectoryMembershipUser class with the specified property values.

Properties

Comment Comment Comment Comment

Gets or sets application-specific information for the membership user.

CreationDate CreationDate CreationDate CreationDate

Gets the date and time when the user was added to the membership data store.

(Inherited from MembershipUser)
Email Email Email Email

Gets or sets the email address of the membership user.

IsApproved IsApproved IsApproved IsApproved

Gets or sets a value that indicates whether the membership user can be authenticated.

IsLockedOut IsLockedOut IsLockedOut IsLockedOut

Gets a value indicating whether the membership user is locked out and unable to be validated.

(Inherited from MembershipUser)
IsOnline IsOnline IsOnline IsOnline

Gets whether the user is currently online.

(Inherited from MembershipUser)
LastActivityDate LastActivityDate LastActivityDate LastActivityDate

Throws a NotSupportedException exception in all cases

LastLockoutDate LastLockoutDate LastLockoutDate LastLockoutDate

Gets the most recent date and time that the membership user was locked out.

(Inherited from MembershipUser)
LastLoginDate LastLoginDate LastLoginDate LastLoginDate

Throws a NotSupportedException exception in all cases.

LastPasswordChangedDate LastPasswordChangedDate LastPasswordChangedDate LastPasswordChangedDate

Gets the date and time when the membership user's password was last updated.

(Inherited from MembershipUser)
PasswordQuestion PasswordQuestion PasswordQuestion PasswordQuestion

Gets the password question for the membership user.

(Inherited from MembershipUser)
ProviderName ProviderName ProviderName ProviderName

Gets the name of the membership provider that stores and retrieves user information for the membership user.

(Inherited from MembershipUser)
ProviderUserKey ProviderUserKey ProviderUserKey ProviderUserKey

Gets the user identifier from the Active Directory data store for the membership user.

UserName UserName UserName UserName

Gets the logon name of the membership user.

(Inherited from MembershipUser)

Methods

ChangePassword(String, String) ChangePassword(String, String) ChangePassword(String, String) ChangePassword(String, String)

Updates the password for the membership user in the membership data store.

(Inherited from MembershipUser)
ChangePasswordQuestionAndAnswer(String, String, String) ChangePasswordQuestionAndAnswer(String, String, String) ChangePasswordQuestionAndAnswer(String, String, String) ChangePasswordQuestionAndAnswer(String, String, String)

Updates the password question and answer for the membership user in the membership data store.

(Inherited from MembershipUser)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetPassword() GetPassword() GetPassword() GetPassword()

Gets the password for the membership user from the membership data store.

(Inherited from MembershipUser)
GetPassword(String) GetPassword(String) GetPassword(String) GetPassword(String)

Gets the password for the membership user from the membership data store.

(Inherited from MembershipUser)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ResetPassword() ResetPassword() ResetPassword() ResetPassword()

Resets a user's password to a new, automatically generated password.

(Inherited from MembershipUser)
ResetPassword(String) ResetPassword(String) ResetPassword(String) ResetPassword(String)

Resets a user's password to a new, automatically generated password.

(Inherited from MembershipUser)
ToString() ToString() ToString() ToString()

Returns the user name for the membership user.

(Inherited from MembershipUser)
UnlockUser() UnlockUser() UnlockUser() UnlockUser()

Clears the locked-out state of the user so that the membership user can be validated.

(Inherited from MembershipUser)

Applies to

See also