MembershipUser Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Exposes and updates membership user information in the membership data store.

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


[SerializableAttribute]
public class MembershipUser

NameDescription
System_CAPS_protmethodMembershipUser()

Creates a new instance of a MembershipUser object for a class that inherits the MembershipUser class.

System_CAPS_pubmethodMembershipUser(String, String, Object, String, String, String, Boolean, Boolean, DateTime, DateTime, DateTime, DateTime, DateTime)

Creates a new membership user object with the specified property values.

NameDescription
System_CAPS_pubpropertyComment

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

System_CAPS_pubpropertyCreationDate

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

System_CAPS_pubpropertyEmail

Gets or sets the e-mail address for the membership user.

System_CAPS_pubpropertyIsApproved

Gets or sets whether the membership user can be authenticated.

System_CAPS_pubpropertyIsLockedOut

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

System_CAPS_pubpropertyIsOnline

Gets whether the user is currently online.

System_CAPS_pubpropertyLastActivityDate

Gets or sets the date and time when the membership user was last authenticated or accessed the application.

System_CAPS_pubpropertyLastLockoutDate

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

System_CAPS_pubpropertyLastLoginDate

Gets or sets the date and time when the user was last authenticated.

System_CAPS_pubpropertyLastPasswordChangedDate

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

System_CAPS_pubpropertyPasswordQuestion

Gets the password question for the membership user.

System_CAPS_pubpropertyProviderName

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

System_CAPS_pubpropertyProviderUserKey

Gets the user identifier from the membership data source for the user.

System_CAPS_pubpropertyUserName

Gets the logon name of the membership user.

NameDescription
System_CAPS_pubmethodChangePassword(String, String)

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

System_CAPS_pubmethodChangePasswordQuestionAndAnswer(String, String, String)

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

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetPassword()

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

System_CAPS_pubmethodGetPassword(String)

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

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodResetPassword()

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

System_CAPS_pubmethodResetPassword(String)

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

System_CAPS_pubmethodToString()

Returns the user name for the membership user.(Overrides Object.ToString().)

System_CAPS_pubmethodUnlockUser()

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

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 e-mail address, and provides functionality for the membership user such as the ability to change or reset his or her password.

System_CAPS_noteNote

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.

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

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

The following code example updates the e-mail address for a user.

System_CAPS_security Security Note

This example contains a text box that accepts user input, which is a potential security threat. 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 e-mail 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>E-mail 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 E-mail" 
                      OnClick="UpdateEmailButton_OnClick" 
                      runat="server" /></td>
    </tr>
  </table>
</form>

</body>
</html>

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: