ActiveDirectoryMembershipUser 类

定义

公开和更新 Active Directory 数据存储区中存储的成员资格用户信息。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
继承
ActiveDirectoryMembershipUser
属性

示例

下面的代码示例演示如何在网页上使用 ActiveDirectoryMembershipUser 对象上的属性,该对象可能会从多个成员资格数据存储中返回用户信息。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. 由于成员资格提供程序返回的 MembershipUser 对象的 ActiveDirectoryMembershipUser 对象未实现 LastActivityDateLastLoginDate 属性,因此在显示这些属性的内容之前,代码首先会检查从成员资格提供程序返回的用户对象的类型。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>

注解

ActiveDirectoryMembershipUser 对象用于表示 Active Directory 成员资格数据存储区中的单个成员资格用户。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.

每当应用程序配置为使用 Active Directory 数据存储时,应用程序的成员资格提供程序都将返回 ActiveDirectoryMembershipUser 对象。An ActiveDirectoryMembershipUser object is returned by the application's membership provider whenever the application is configured to use an Active Directory data store. 在可配置为使用不同数据存储的应用程序中,或者在使用多个数据存储的应用程序中,可以引用基类 MembershipUserIn 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. 由于 ActiveDirectoryMembershipUser 对象未实现 LastActivityDateLastLoginDate 属性,因此您必须准备好处理在 ActiveDirectoryMembershipUser 对象上访问这些成员时引发的 NotSupportedExceptionBecause 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.

ActiveDirectoryMembershipUser 类实现了 ActiveDirectoryMembershipProvider 类使用的内部优化,以最大程度地减少调用 UpdateUser 方法时所发生的属性更新的数目。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. 它还会序列化 SecurityIdentifier 表示形式(在 ProviderUserKey 属性中可用),以便在不引发异常的情况下序列化和反序列化 ActiveDirectoryMembershipUser 对象。It also serializes the SecurityIdentifier representation (available in the ProviderUserKey property) so that an ActiveDirectoryMembershipUser object can be serialized and deserialized without throwing exceptions.

ActiveDirectoryMembershipUser 对象由 GetUserCreateUser 方法返回,或作为 GetAllUsersFindUsersByNameFindUsersByEmail 方法返回的 MembershipUserCollection 的一部分返回。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.

当您想要更新现有成员资格用户的信息时,UpdateUser 方法需要 ActiveDirectoryMembershipUser 的对象。An ActiveDirectoryMembershipUser object is required by the UpdateUser method when you want to update the information for an existing membership user.

ActiveDirectoryMembershipUser 属性映射到 Active Directory 属性。ActiveDirectoryMembershipUser properties are mapped to Active Directory attributes. 下表列出了 ActiveDirectoryMembershipUser 属性及其默认属性映射。The following table lists the ActiveDirectoryMembershipUser properties and their default attribute mappings.

propertiesProperty 默认目录属性Default directory attribute 是否可以映射?Can be mapped?
ProviderUserKey securityIdentifier No
UserName userPrincipalName 是,但必须是 userPrincipalName 或 sAMAccountNameYes, but must be either userPrincipalName or sAMAccountName
Comment comment No
CreationDate whenCreated No
Email mail 是,但必须是 Unicode 字符串类型的单值属性。Yes, but must be a single-valued attribute of type Unicode String.
LastActivityDate 不适用n/a 不受 ActiveDirectoryMembershipProvider 支持。Not supported by ActiveDirectoryMembershipProvider.
LastLoginDate 不适用n/a 不受 ActiveDirectoryMembershipProvider 支持。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. 是,但必须是 Unicode 字符串类型的单值属性。Yes, but must be a single-valued attribute of type Unicode String.
IsApproved User-Account-Control (AD)User-Account-Control (AD)

mDS-UserAccountDisabled (ADAM)mDS-UserAccountDisabled (ADAM)
No
IsLockedOut lockoutTime 和 AD 锁定持续时间(Windows 2000 上的 AD)进行计算computed from lockoutTime and the AD lockout duration (AD on Windows 2000)

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

msDS-User-Account-Control-Computed (ADAM)msDS-User-Account-Control-Computed (ADAM)
No
LastLockoutDate 如果由于无效密码尝试次数过多而被锁定,则返回 "锁定时间" 属性。If locked out due to too many bad password attempts, the lockout time attribute is returned.

如果因错误密码答案尝试次数过多而被锁定,则将返回 attributeMapFailedPasswordAnswerLockoutTime 定义的属性中存储的值。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.

如果该帐户未锁定,则返回1/1/1753 以了解 SQL 兼容性。If the account is not locked out, return 1/1/1753 for SQL compatibility.
No

构造函数

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 类的新实例。Creates a new instance of the ActiveDirectoryMembershipUser class with the specified property values.

属性

Comment

获取或设置成员资格用户的应用程序特定信息。Gets or sets application-specific information for the membership user.

CreationDate

获取将用户添加到成员资格数据存储的日期和时间。Gets the date and time when the user was added to the membership data store.

(继承自 MembershipUser)
Email

获取或设置成员资格用户的电子邮件地址。Gets or sets the email address of the membership user.

IsApproved

获取或设置一个值,该值指示成员资格用户是否可以进行身份验证。Gets or sets a value that indicates whether the membership user can be authenticated.

IsLockedOut

获取一个值,该值指示成员资格用户是否已锁定而无法验证。Gets a value indicating whether the membership user is locked out and unable to be validated.

(继承自 MembershipUser)
IsOnline

获取用户当前是否处于联机状态。Gets whether the user is currently online.

(继承自 MembershipUser)
LastActivityDate

在所有情况下都会引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases.

LastLockoutDate

获取成员资格用户被锁定的最新日期和时间。Gets the most recent date and time that the membership user was locked out.

(继承自 MembershipUser)
LastLoginDate

在所有情况下都会引发 NotSupportedException 异常。Throws a NotSupportedException exception in all cases.

LastPasswordChangedDate

获取成员资格用户密码的上次更新日期和时间。Gets the date and time when the membership user's password was last updated.

(继承自 MembershipUser)
PasswordQuestion

获取成员资格用户的密码问题。Gets the password question for the membership user.

(继承自 MembershipUser)
ProviderName

获取成员资格提供程序的名称,该提供程序存储并检索成员资格用户的用户信息。Gets the name of the membership provider that stores and retrieves user information for the membership user.

(继承自 MembershipUser)
ProviderUserKey

从 Active Directory 数据存储区获取成员资格用户的用户标识符。Gets the user identifier from the Active Directory data store for the membership user.

UserName

获取成员身份用户的登录名。Gets the logon name of the membership user.

(继承自 MembershipUser)

方法

ChangePassword(String, String)

在成员资格数据存储中更新成员资格用户的密码。Updates the password for the membership user in the membership data store.

(继承自 MembershipUser)
ChangePasswordQuestionAndAnswer(String, String, String)

为成员资格数据存储中的成员资格用户更新密码问题和答案。Updates the password question and answer for the membership user in the membership data store.

(继承自 MembershipUser)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetPassword()

从成员资格数据存储中获取成员资格用户的密码。Gets the password for the membership user from the membership data store.

(继承自 MembershipUser)
GetPassword(String)

从成员资格数据存储中获取成员资格用户的密码。Gets the password for the membership user from the membership data store.

(继承自 MembershipUser)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ResetPassword()

将用户密码重置为自动生成的新密码。Resets a user's password to a new, automatically generated password.

(继承自 MembershipUser)
ResetPassword(String)

将用户密码重置为自动生成的新密码。Resets a user's password to a new, automatically generated password.

(继承自 MembershipUser)
ToString()

返回成员资格用户的用户名。Returns the user name for the membership user.

(继承自 MembershipUser)
UnlockUser()

清除用户锁定状态,以便验证成员资格用户。Clears the locked-out state of the user so that the membership user can be validated.

(继承自 MembershipUser)

适用于

另请参阅