MembershipUser Class
Assembly: System.Web (in system.web.dll)
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.
Note: |
|---|
|
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.
| Topic | Location |
|---|---|
| How to: Implement a Custom Membership User | Building ASP .NET Web Applications |
| How to: Implement a Custom Membership User | Building ASP .NET Web Applications |
The following code example updates the e-mail address for a user.
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 (Visual Studio). |
<%@ 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>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Reference
MembershipUser MembersSystem.Web.Security Namespace
Note: