MembershipUser 类

定义

公开和更新成员资格数据存储区中的成员资格用户信息。Exposes and updates membership user information in the membership data store.

public ref class MembershipUser
[System.Serializable]
public class MembershipUser
type MembershipUser = class
Public Class MembershipUser
继承
MembershipUser
派生
属性

示例

下面的代码示例将更新用户的电子邮件地址。The following code example updates the email address for a user.

重要

此示例包含一个文本框,该文本框接受用户输入,这是一个潜在的安全威胁。This example contains a text box that accepts user input, which is a potential security threat. 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述For more information, see Script Exploits Overview.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

MembershipUser u;

public void Page_Load(object sender, EventArgs args)
{
  u = Membership.GetUser(User.Identity.Name);

  if (!IsPostBack)
  {
    EmailTextBox.Text = u.Email; 
  }
}

public void UpdateEmailButton_OnClick(object sender, EventArgs args)
{
  try
  {
    u.Email = EmailTextBox.Text;

    Membership.UpdateUser(u);
  
    Msg.Text = "User email updated.";
  }
  catch (System.Configuration.Provider.ProviderException e)
  {
    Msg.Text = e.Message;
  }
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Update User E-Mail</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Update E-Mail Address for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  <table cellpadding="3" border="0">
    <tr>
      <td>Email Address:</td>
      <td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                    ControlToValidate="EmailTextBox" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td></td>
      <td><asp:Button id="UpdateEmailButton" 
                      Text="Update Email" 
                      OnClick="UpdateEmailButton_OnClick" 
                      runat="server" /></td>
    </tr>
  </table>
</form>

</body>
</html>
<%@ Page Language="vb" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Dim u As MembershipUser

Public Sub Page_Load(sender As Object, args As EventArgs)

  u = Membership.GetUser(User.Identity.Name)

  If Not IsPostBack Then EmailTextBox.Text = u.Email

End Sub

Public Sub UpdateEmailButton_OnClick(sender As Object, args As EventArgs)

  Try
    u.Email = EmailTextBox.Text

    Membership.UpdateUser(u)
  
    Msg.Text = "User email updated."
  Catch e As System.Configuration.Provider.ProviderException
    Msg.Text = e.Message
  End Try

End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Update User E-Mail</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Update E-Mail Address for <%=User.Identity.Name%></h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  <table cellpadding="3" border="0">
    <tr>
      <td>Email Address:</td>
      <td><asp:TextBox id="EmailTextBox" MaxLength="128" Columns="30" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                    ControlToValidate="EmailTextBox" ForeColor="red"
                                    Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td></td>
      <td><asp:Button id="UpdateEmailButton" 
                      Text="Update Email" 
                      OnClick="UpdateEmailButton_OnClick" 
                      runat="server" /></td>
    </tr>
  </table>
</form>

</body>
</html>

注解

MembershipUser对象用于表示成员资格数据存储区中的单个成员资格用户。The MembershipUser object is used to represent a single membership user in the 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.

备注

如果你不熟悉 ASP.NET 的成员资格功能,请参阅 "成员资格简介",然后继续。If you are not familiar with the membership features of ASP.NET, see Introduction to Membership before continuing. 有关与成员资格相关的其他主题的列表,请参阅使用成员身份管理用户For a list of other topics related to membership, see Managing Users by Using Membership.

MembershipUser对象MembershipUserCollection由和方法返回GetAllUsers,或由、FindUsersByName和方法FindUsersByEmail返回的组成。 GetUser CreateUserA MembershipUser object is returned by the GetUser and CreateUser methods or as part of a MembershipUserCollection returned by the GetAllUsers, FindUsersByName, and FindUsersByEmail methods.

如果要更新现有成员资格UpdateUser用户的信息,则方法需要对象。MembershipUserA MembershipUser object is required by the UpdateUser method when you want to update the information for an existing membership user.

构造函数

MembershipUser()

为继承 MembershipUser 类的类创建一个 MembershipUser 对象的新实例。Creates a new instance of a MembershipUser object for a class that inherits the MembershipUser class.

MembershipUser(String, String, Object, String, String, String, Boolean, Boolean, DateTime, DateTime, DateTime, DateTime, DateTime)

使用指定的属性值创建新的成员资格用户对象。Creates a new membership user object 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.

Email

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

IsApproved

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

IsLockedOut

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

IsOnline

获取一个值,表示用户当前是否联机。Gets whether the user is currently online.

LastActivityDate

获取或设置成员资格用户上次进行身份验证或访问应用程序的日期和时间。Gets or sets the date and time when the membership user was last authenticated or accessed the application.

LastLockoutDate

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

LastLoginDate

获取或设置用户上次进行身份验证的日期和时间。Gets or sets the date and time when the user was last authenticated.

LastPasswordChangedDate

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

PasswordQuestion

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

ProviderName

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

ProviderUserKey

从用户的成员资格数据源获取用户标识符。Gets the user identifier from the membership data source for the user.

UserName

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

方法

ChangePassword(String, String)

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

ChangePasswordQuestionAndAnswer(String, String, String)

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

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.

GetPassword(String)

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

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.

ResetPassword(String)

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

ToString()

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

UnlockUser()

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

适用于

另请参阅